Warning message

Documentation is currently being migrated into the new system. Some pages might be temporary missing, and some guides might appear empty. Thank you for you patience while we are improving Drupal.org documentation.

Tuning php.ini for Drupal

Last updated on
August 16, 2016 - 20:18
  • Finding out current PHP memory limit and php.ini location
  • Edit PHP’s realpath-cache-size, and realpath-cache-ttl for Drupal

Finding out current PHP memory limit and php.ini location

To find out the current value of PHP memory limit, navigate to status report (Reports > Status report or http://example.com/admin/reports/status) and scroll down (items are listed alphabetically) to PHP:

Status report

Two lines above that, you can see PHP version info; 'more information' link takes you to phpinfo() page, where you can find out the location of php.ini file:

phpinfo()
(example from a Linux (Ubuntu) system)

To increase PHP memory limit follow instructions.

Edit PHP’s realpath-cache-size, and realpath-cache-ttl for Drupal

Editing the following php.ini directives can noticeably decrease Drupal's initial page generation times.

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 (such as Drupal), to reflect the quantity of the file operations performed. The default value of this declaration is 16k, and should be changed to a value that represents the actual amount of memory used for realpath cache.

In order to find the actual amount of memory that is used by realpath cache, you’ll need to increase the default amount that is being used currently to a larger number than 16k (try 256k) and then use a script to print the actual amount to the screen. I’ve found it helpful to create a PHP block that prints out the actual value and set it to only be visible to my particular role. Then I can check memory intensive areas as well as regular pages. Once I’m done, I’ll disable the block as it’s not needed anymore.

Set realpath cache to 256k in php.ini:

realpath_cache_size = 256k

Create a php block or otherwise inject the following php into your site so that you can view it on the screen:



  print_r(realpath_cache_size());
 

The majority of sites I've checked using this method are using less than 64k. Your values will likely be different.

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 (such as Drupal), consider increasing the value. Raise this to 300 or higher.

The following are settings used in a Drupal site for a member’s organization that serves approximately 1500 users and more importantly the site has roughly 30 contributed modules + CiviCRM on the backend which results in quite a number of files requested.

realpath_cache_size = 64k
realpath_cache_ttl = 3600