SW Designs

Technology and Photography

Tuning PHP

Despite being introduced in PHP 5.1.0 that was released in late 2005, there are a pair of less well known php.ini directives that can have a noticeable affect on performance, especially for developers who work with spagetti code. These options control how PHP files are cached internally by PHP when using, for example, the include/require constructs (not functions!). These options are,

realpath_cache_size

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_ttl

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 the value.

So why should people care about these options? Well, everytime that a file is loaded using a relative path PHP first has to lookup where that file exists on the filesystem. Once cached futher includes will be far cheaper, however with small cache size by default entries will quickly churn when you consider that PHP frameworks such as Zend Framework contain well over a thousand files.

So what should it be set to? Well that largely depends on your personal situation, those with extreme symptoms of spaghetti-code-itous which vast numbers of library files should use higher values. Personally, on my modest Zend Framework installation I find a cache size of 128KB works well. As for the time to live (ttl) value this defaults to 2 minutes and should be tweaked on a per-case basis depending on how frequently the application is updated.

References,

  1. http://uk.php.net/ini.core

Comments