Why would apc_store() return false?

旧巷老猫 提交于 2019-11-30 11:38:36

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

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.

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

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') );

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.

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

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

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

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.

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