Why would apc_store() return false?

限于喜欢 提交于 2019-11-29 16:56:58

问题


The documentation on php.net is very spotty about causes of failure for APC writes. What kind of scenarios would cause a call to apc_store() to fail?

There's plenty of disk space available, and the failures are spotty. Sometimes the store operation will succeed and sometimes it'll fail.


回答1:


out of memory (allocated memory for apc, that is)




回答2:


For php cli it needs to be enabled with another option: apc.enable_cli=On

In my situation it was working when running from a webbrowser, but not when executing the same stuff with php cli.




回答3:


I had exactly the same situation.

I migrated my code from using Cron Jobs, to using Gearman Workers, which were managed through supervisord.

Everything Broke. I couldn't ever get caches to work through APC, and had to revert back to using filebase caching.

Eventually I figured out that when I was using cron jobs, I would load each page via wget, rather than command line. This difference, meant that supervisord, which would load my PHP scripts via command line, wouldn't work, because by default APC will not work through command line.

The fix....

apc.enable_cli=On




回答4:


this asinine (and closed, for some reason) bug was my problem:

http://pecl.php.net/bugs/bug.php?id=16814

has to roll back to apc version 3.1.2 to get apc to work. no fiddling with apc settings in php.ini helped (i'm on mac os 10.5, using apache 2, php 5.3).

for me, this test script showed 3 "trues" for 3.1.2 and true/false/true for 3.1.3p1

var_dump( apc_store('test', 'one') ); var_dump( apc_store('test', 'two') ); var_dump( apc_store('diff', 'thr') );




回答5:


http://php.net/manual/en/apc.configuration.php

the apc.ttl and apc.user_ttl settings on php.ini:

Leaving this at zero means that APC's cache could potentially fill up with stale entries while newer entries won't be cached.




回答6:


Out of disk space or permission denied to the storage directory?




回答7:


In addition to what Greg said, I'd add that a configuration error could cause this.




回答8:


apc_store will fail if that specific key already exists and you are trying to write again to it before the TTL expires. Therefore you can pretty much ignore the return false because it really did fail but the cache is still there. If you want to get around this, start using apc_add instead. http://php.net/manual/en/function.apc-add.php




回答9:


There's a bug in the version installed with ubuntu 10.04 and debian stable. If you replace the package with this version: http://packages.debian.org/sid/php-apc (3.1.7) it works as it should.



来源:https://stackoverflow.com/questions/1670034/why-would-apc-store-return-false

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