为什么 apc_store() 返回 false?
php.net 上的文档对于 APC 写入失败的原因非常参差不齐。什么样的场景会导致 apc_store() 调用失败?
有足够的可用磁盘空间,而且故障也时有发生。商店运营有时会成功,有时会失败。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果该特定密钥已存在并且您尝试在 TTL 过期之前再次写入该密钥,则 apc_store 将失败。因此,您几乎可以忽略返回 false,因为它确实失败了,但缓存仍然存在。如果您想解决这个问题,请开始使用 apc_add 。 http://php.net/manual/en/function.apc-add。 php
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
对于 php cli,需要使用另一个选项启用:
apc.enable_cli=On
在我的情况下,它在从网络浏览器运行时可以工作,但在使用 php cli 执行相同的内容时则不行。
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.
我也有同样的情况。
我将代码从使用 Cron Jobs 迁移到使用 Gearman Workers,后者通过supervisord 进行管理。
一切都破碎了。我无法让缓存通过 APC 工作,并且不得不恢复使用文件库缓存。
最终我发现当我使用 cron 作业时,我会通过 wget 而不是命令行加载每个页面。这种差异意味着通过命令行加载我的 PHP 脚本的supervisord 无法工作,因为默认情况下 APC 不会通过命令行工作。
修复....
apc.enable_cli=On
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
内存不足(即为 apc 分配的内存)
out of memory (allocated memory for apc, that is)
这个愚蠢的(并且由于某种原因已关闭)错误是我的问题:
http:// /pecl.php.net/bugs/bug.php?id=16814
必须回滚到 apc 版本 3.1.2 才能使 apc 正常工作。无需摆弄 php.ini 中的 apc 设置有帮助(我在 mac os 10.5 上,使用 apache 2,php 5.3)。
对我来说,这个测试脚本显示 3.1.2 的 3 个“true”和 3.1.3p1 的 true/false/true
var_dump( apc_store('test', 'one') );
var_dump( apc_store('测试', '两个') );
var_dump( apc_store('diff', 'thr') );
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
php.ini 上的 apc.ttl 和 apc.user_ttl 设置:
http://php.net/manual/en/apc.configuration.php
the apc.ttl and apc.user_ttl settings on php.ini:
磁盘空间不足或存储目录权限被拒绝?
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.
使用 ubuntu 10.04 和 debian stable 安装的版本存在错误。如果您用此版本替换软件包: http://packages.debian.org/sid/php- apc (3.1.7) 它按预期工作。
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.