5

I've got APC up and running on my VPS and have installed the APC module on my Drupal 7 site. I followed the documentation here and added this code to my settings.php file:

$conf['cache_backends'] = array('sites/all/modules/apc/drupal_apc_cache.inc');
$conf['cache_default_class'] = 'DrupalAPCCache';
//$conf['apc_show_debug'] = TRUE;  // Remove the slashes to use debug mode.

However, on my site's status page under APC, it says:

APC has been running for 3 min 54 sec. Currently caching 0 entries (0 bytes).

To me the "0 entries" indicated that there was no cache being created / used. I did some digging around and it looks like there might be additional code I need to add but cannot find documentation anywhere.

I found this snippet but not really sure if I need it or what part it I am supposed to use and what it does, I could not find any documentation for this. I suspect this is what makes the cache work.

'page_cache_without_database' => TRUE,
        'page_cache_invoke_hooks'     => FALSE,
        'page_cache_maximum_age'      => 3600,
        'cache_lifetime'              => 0,
        /* my note -- noticed "cacherouter" in the path below 
         so I am guessing this needs to be adapeted to the path for APC?? */
        'session_inc'      => './sites/all/modules/cacherouter/session.inc',
            'cache_default_class'               => 'DrupalAPCCache',
            'cache_class_cache'                 => 'DrupalAPCCache',
            'cache_class_cache_block'           => 'DrupalAPCCache',
            'cache_class_cache_bootstrap'       => 'DrupalAPCCache',
            'cache_class_cache_content'         => 'DrupalAPCCache',
            'cache_class_cache_filter'          => 'DrupalAPCCache',
            'cache_class_cache_form'            => 'DrupalAPCCache',
            'cache_class_cache_menu'            => 'DrupalAPCCache',
            'cache_class_cache_page'            => 'DrupalAPCCache',
            'cache_class_cache_pathdst'         => 'DrupalAPCCache',
            'cache_class_cache_pathsrc'         => 'DrupalAPCCache',
            'cache_class_cache_session'         => 'DrupalAPCCache',
            'cache_class_cache_session_user'    => 'DrupalAPCCache',
            'cache_class_cache_update'          => 'DrupalAPCCache',
            'cache_class_cache_users'           => 'DrupalAPCCache',
            'cache_class_cache_views'           => 'DrupalAPCCache',
            'cache_class_cache_views_data'      => 'DrupalAPCCache',
      );

Any help on this matter would be appreciated.

The information about the APC extension returned from phpinfo() are the following ones.

screenshot

  • 1
    Is this on linux ? What is in your php info in the "apc" section? Do you run php-fpm master process ? – Refineo Apr 2 '12 at 17:37
  • It's on linux / Cent OS. Here is a screen capture of the APC section: twitpic.com/94re56/full I am not familiar with php-fpm so not sure about that... – Danny Englander Apr 2 '12 at 17:44
  • 1
    Note: I've had quite some issues with using APC as cache backend, APC tends to become instable when you have large amounts of caches. I'd recommend using an external (=outside of PHP) service as cache provider, for example Memcache or Redis. – Berdir Apr 2 '12 at 18:54
6

"APC has been running for 3 min 54 sec. Currently caching 0 entries (0 bytes)."

This message suggests that your APC is running for each php request separately ultimately not caching anything at all.

I had a similar issue and it required to set up PHP once again but in a different mode.

APC works fine for multiple processes with apache/2 + php 5.3.x + php-fpm + fcgi in FPM/FastCGI mode.

PHP 5.3.x is configured with following options --enable-force-cgi-redirect --enable-fastcgi --enable-fpm

In APC section of my php info I can see:

APC Support = enabled Serialization Support = php MMAP File Mask = /tmp/apc.something | where something is a random 6-character string

Please check your phpinfo

In PHP Configure Command you should have: '--enable-fastcgi' and '--enable-fpm'

In Server API : FPM/FastCGI

Check if you have cgi-fcgi section and if you can find php-fpm set to "active"

NOTE: There might be another solution if you use php 5.2.x or older.

  • Thanks that's all very interesting info but it does not address the crux of my basic question, "what about the additional code required for settings.php"... – Danny Englander Apr 2 '12 at 19:19
  • Sorry, I can only tell you that manipulation of settings.php was not enough in my case and I needed to ask to recompile php and install php-fpm together with it. – Refineo Apr 2 '12 at 19:23
3

APC should only be used for smaller parts of the cache, that dont change frequently. So probably not pages for example. (the actual bins where it is wise to use APC may vary depending on the site ... for example vars or menu).

Indeed, before you start caching data, first fine-tune your settings for caching scripts (so turn of that module).

You should use the script apc.php to see how much memory was used to cache the scripts and make sure you give APC enough memory (the default setting - 32M in your case is not necessarily enough) - otherwise the cache can be even worse - slowing the site down by trying to cache again and again. If you are limited on resources, dont be afraid to give it a fair share - it pays off (a tuned apc can get you lower amount of RAM per pageview).

I was also playing with not caching some directories (a crazy module with a lot files or the admin parts of views for example). Also, remember that in the default setting it is trying to cache ANY php file on the VPS ... even running two drupals side by side can be problematic (newly visited code is pushing the older out of the cache) - so i suggest limiting it to one drupal.

this is a useful resource to see http://php.net/manual/en/apc.configuration.php and one with relation to drupal : http://xerosphere.net/optimizing-apc-for-drupal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.