Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APC doesn't cache files, but caches user data

Tags:

linux

php

apc

Apc doesn't cache files, it only caches user data. When I tested on localhost, APC cached all files I used. But it doesn't work on my shared hosting. Is this a configuration issue?

These are the stats from my apc.php (APC 3.0.19): apc.php stats

On the above picture, APC doesn't use any memory. This is what phpinfo() gives me: phpinfo() output

On localhost, i only access http://localhost/test.php. Apc will cache localhost/test.php ( type file ) imediately. but on shared host, i don't see it cache file ( it can cache variable, if i store but don't with file );

    apc_add('APC TEST', '123');
    echo apc_fetch('APC TEST'); //-- it work with this code

i want Apc cache test.php if i access test.php.

Is there a configure make APC can't cache file type or it is limit of shared hosting?.

like image 772
meotimdihia Avatar asked Apr 01 '11 06:04

meotimdihia


1 Answers

In response to your comment "Apc is enabled , and apc.cache_by_default = 1; php setup with CGI, i checked phpinfo();": That's the problem. If you run PHP over CGI a new PHP process is created on every page load. As APC is bound to the PHP process it is newly instantiated on every page access, too. So it obviously doesn't have any data in it. Your user cache example only works, because you store and fetch the variable on a single page load.

So: APC can not work with PHP over CGI. Use FastCGI (which keeps the processes alive, thus making the Cache work and generally being faster).

like image 169
NikiC Avatar answered Nov 19 '22 19:11

NikiC