Speed up Drupal with realpath cache
When your Drupal instance becomes sluggish, there are a number of recommended steps to take (check page cache, use APC/memcached/varnish).
Oftentimes, the issue lies in the number of files PHP has to open during the Drupal bootstrap. It is directly related to the number of enabled modules, which at times you simply cannot reduce.
In addition to the default recommendations, one should check the realpath_cache_size
option in php.ini
The default is 16k, but increasing it to something like 256k will shave off seconds from the processing time.
; Determines the size of the realpath cache to be used by PHP. This value should
; be increased on systems where PHP opens many files to reflect the quantity of
; the file operations performed.
; realpath_cache_size=16k
realpath_cache_size=256k
Moreover, for systems with files that do not change often, the realpath_cache_ttl
time can be increased from the default 120 seconds.
; Duration of time, in seconds for which to cache realpath information for a given
; file or directory. For systems with rarely changing files, consider increasing this
; value.
; realpath_cache_ttl=120
realpath_cache_ttl=300
Written by Dan Braghis
Related protips
1 Response
Nice tip - but it's a shame more PHP webapps turn to using absolute require/include calls instead of relative paths - which is rather trivial with __FILE__ and __DIR__ (5.3+) magic constants in PHP.
Using an absolute path skips use of the realpath cache completely so this becomes a non-issue as PHP doesn't need to convert a relative -> absolute path and then cache the result.