📜 ⬆️ ⬇️

Forcing open_basedir + realpath_cache to work together

Noticing some slowdown in PHP performance on constant lstat checks of all the paths of opened files and directories, I decided to tune the performance by increasing realpath_cache_size. I was a little surprised when I got out
var_dump(realpath_cache_size(),realpath_cache_get()); 

  int (0);  array (0) {} 


Even more surprised that this bug has not yet been resolved in recent versions of PHP 5.6, and there is not a word about it in the documentation (one user comment a month ago).

A solution was found with some googling: an extension that combines open_basedir in itself and works through the PHP paths cache. Turbo_realpath .
')
It is not in Pecl, so we download the archive from the offsite (for versions 5.4+, see the offsite below).

Installation in the console:
 unzip realpath_turbo_1.2.zip cd realpath_turbo phpize ./configure make make install 


In php.ini or, for example, in my debian-like, I have my own configuration for a separate extension:
 extension=turbo_realpath.so 


replace open_basedir settings
 # clear all open_basedir restrictions open_basedir="" # replace it with realpath_cache_basedir = /var/www/html/drupal 


The extension may have some more security improvements:
 ; set this to 1 in order to disable dangerous PHP functions (link,symlink), or set to 0 in order to ignore potential security issues <video></video>;   1    PHP  (link,symlink),   0      realpath_cache_security = 1 ; if you want, you can enable safe_mode, in order to do so, you have to switch off ; standard open_basedir setting... ;  ,   safe_mode,   ,     open_basedir open_basedir = off ; and then switch on custom realpath_cache_open_basedir setting, ; (remember, safe mode is not required by realpath_turbo extension, ; you can safely ignore these settings if you want) ;     realpath_cache_open_basedir ; (, safe mode     realpath_turbo,      ,  ) real_path_cache_safe_mode = on 

Source: https://habr.com/ru/post/270435/


All Articles