Skip to main content
right APC memory

Knowing the right APC memory needed for your Drupal site

Alternative PHP Cache (APC) is one of the best PHP accelerators around for a while.

Wikipedia ideally describes the same as below,

Alternative PHP Cache is a free, open source (PHP license) framework that caches the output of the PHP bytecode compiler in shared memory, thus reducing parsing and disk I/O overhead for later requests; and a shared memory cache for user data. For an application consisting of a large source code base such as Drupal, a 3x increase in page generation speed is possible as a result.

As mentioned the complied bytecode is loaded into the RAM to speed up the execution of consecutive requests.

Almost for every Drupal sites we use APC to keep the response time within the ideal range. But knowing how much of RAM to block for APC helps to leverage best of framework and possibility prevents from under utilizing the expensive resource (RAM).

While working in my recent projects, I came across a script, apc.php which helps to find answer for this question. Since it is being shipped with official framework package, it is trustworthy and needs no configuration to get started.

We prefer Ubuntu LTS for our Drupal servers. In our case, apc.php was found at /usr/share/doc/php-apc/apc.php.gz.

Utility commands like locate (# locate apc.php) could help to return its absolute path, in case it's different in your distribution.

On decompressing the .gz with gunzip or similar the actual script can be recovered. Move the same to document root of your Web server. Now with your domain name, say https://example.php/apc.php you can see the stats and arrive the ideal memory needed for your site. 

Sample stats from one of our sites,

Another essential stuff to note is Hits & Misses. In our case it is 98.9%, close to ideal. Based on this value, we might consider for revising configuration as needed.