APC doesn't cache files, but caches user data

点点圈 提交于 2019-12-22 06:37:39

问题


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):

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

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?.


回答1:


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).




回答2:


APC in CGI mode on shared hosting is generally not feasible although it may be possible. Depending on your application it may also be a security risk. As nikic said you should be able to get it working with FastCGI but even that it not easy depending on your host. Here is a detailed account of someone that got it working. It may give you some help in trying to get it to work in CGI mode

FastCGI with a PHP APC Opcode Cache




回答3:


If your hosting is setup with php in fastcgi mode APC may not work. can you check this with a standard phpinfo() page? edit: I stand corrected, the chosen answer is right. I confused CGI/fastcgi. yeah CGI will not work. But I want to note that even fastcgi is not that great with opcode caching.



来源:https://stackoverflow.com/questions/5509962/apc-doesnt-cache-files-but-caches-user-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!