如何让APC(PHP缓存)发挥作用?
我读过有关 APC 的信息,它可以加速多个 php 文件站点。所以我在 PHP 中有一个包含许多文件的特定项目,我发现 require_once 和仅解析类定义(不执行它们)花费了大部分时间。
所以我在我的 CentOS 5 服务器上安装了 APC。我将 apc.php 移至我的网络服务器,它显示
Hits: 1 (50.0%)
Misses: 1 (50.0%)
Cached Files 1 (281.1 KBytes)
我可以访问网站并更改子页面等,而 apc.php 仍然只显示一个缓存文件?
在 phpinfo() 中它显示:
APC 支持已启用
我不知道该怎么办。 APC 是否正常工作(如 phpinfo() sais)?浏览我网站上的一些页面后,只有一个缓存文件并不多。
更进一步,如何诊断错误并确保 APC 正常工作?我浏览过
apc.mmap_file_mask /tmp/apc.QnLqNf /tmp/apc.QnLqNf
Directory /tmp 但我那里没有任何 apc 文件,就像 phpinfo 中所述应该发生。
请帮我检查 APC 是否工作,如果不工作,可能是什么问题。
I've read about APC that it speeds up multiple php file sites. So I have this particular project in PHP with many files and i discover that require_once and parsing only class definitions (without executing them) takes most time.
So I've installed APC on my CentOS 5 server. I moved apc.php to my webserver and it displays
Hits: 1 (50.0%)
Misses: 1 (50.0%)
Cached Files 1 (281.1 KBytes)
And I can go to website and change subpages and so on, and apc.php still shows only one cached file ??
And in phpinfo() it shows that:
APC Support enabled
I don't know what to do. Is APC working (like phpinfo() sais) or is it not? Only one cached file is not much after browsing some pages on my website.
And further more how to diagnose errors and make sure that APC works? I've browsed
apc.mmap_file_mask /tmp/apc.QnLqNf /tmp/apc.QnLqNf
Directory /tmp but I don't have any files of apc there like it's stated in phpinfo should occur.
Please help me check if APC is working and if not, what can be a problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
APC 可以通过两种方式使用:
(1)主要效益。它通过存储“编译”脚本的操作码结果来减少脚本执行时间。
至于它的工作原理,来自安装说明:
因此,您在 CentOS 上不需要它(或看到任何活动)。
话虽如此,require/include 比 require_once/include_once/autoload 更好,但只有当您对数百个文件执行此操作时才重要。
APC can be used in two ways:
(1) is the main benefit. It reduces time for script execution by storing the opcode results of "compiling" scripts.
As for it working, from the installation instructions:
So you shouldn't need it (or see any activity) on CentOS.
That being said, require/include are better than require_once/include_once/autoload but it should only matter if you are doing that with hundreds of files.
您的网站基本上是一个 PHP 文件,然后包含或需要其他文件吗?这可能只是注册为一个文件。另外,据我所知,条件包含/要求逻辑可能不会按预期缓存,尽管这可能只是传闻!
Is your site basically one PHP file that then includes or requires other files? That may register as just a single file. Also, as far as I know, conditional include/require logic may not cache as expected though that may just be hearsay!
您检查过日志文件吗?查看 /var/log/apache2/error.log 或者它在您的发行版下的命名。
另外,尝试创建 2-3 个 php 文件,将浏览器指向它们,然后检查 APC 缓存缓存了多少 php 文件。
不确定 APC,但我推荐 Eaccelerator (http://eaccelerator.net/)。我前段时间测试过它,确实有所作为。
Did you check thr log files? take a look at /var/log/apache2/error.log or however its named under your distribution.
Also, try to make 2-3 php files, point thebrowser at them, and then check how many php files are cached by the APC cache..
Not sure about APC, but i'd recommend Eaccelerator (http://eaccelerator.net/). I've tested it some time ago and really made a difference.
APC 实际上并不在进程之间共享缓存。
尝试配置您的 PHP 进程以分叉 Childs 并让主 PHP 进程保持运行。
请参阅:如何共享 APC在 FastCGI 下运行时在多个 PHP 进程之间进行缓存?
APC actually doesnt share cache between proceses.
Try to configure your PHP-Process to fork Childs and let the Master PHP-Process stay running.
See: How to share APC cache between several PHP processes when running under FastCGI?
在 APC 3.1.5dev 分支中,a引入了新选项,允许您禁用操作码缓存。 默认情况下它似乎处于关闭状态。
尝试将其添加到您的 APC 配置文件中:
In the APC 3.1.5dev branch, a new option was introduced allowing you to disable the opcode cache. It appears to be turned off by default.
Try adding this to your APC config file:
http://www.litespeedtech.com/support/forum/showthread.php ?t=3761
“APC 不能很好地与 PHP suEXEC 配合使用,因为每个 PHP 进程都将使用自己的缓存,而不是共享的。
如果您需要使用 PHP suEXEC,您应该尝试 eAccelerator + /dev/shm。”
好有同样的问题,看来 PHP suEXEC + APC 是问题
http://www.litespeedtech.com/support/forum/showthread.php?t=3761
"APC does not work well with PHP suEXEC as each PHP process will use its own cache memory, not shared.
You should try eAccelerator + /dev/shm if you need to use PHP suEXEC."
well got same problem, it seems PHP suEXEC + APC is problem