如何使 APC(PHP 缓存)工作?
我读过关于 APC 的文章,它可以加速多个 php 文件站点.所以我在 PHP 中有一个包含许多文件的特定项目,我发现 require_once 和只解析类定义(不执行它们)需要大部分时间.
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.
所以我在我的 CentOS 5 服务器上安装了 APC.我将 apc.php 移动到我的网络服务器并显示
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)
我可以去网站更改子页面等等,apc.php仍然只显示一个缓存文件??
And I can go to website and change subpages and so on, and apc.php still shows only one cached file ??
在 phpinfo() 中显示:
And in phpinfo() it shows that:
APC 支持启用
我不知道该怎么办.APC 是否正常工作(如 phpinfo() sais)?浏览我网站的某些页面后,只有一个缓存文件并不多.
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.
还有更多如何诊断错误并确保 APC 正常工作?我浏览过
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
apc.mmap_file_mask /tmp/apc.QnLqNf /tmp/apc.QnLqNf
目录/tmp 但我没有任何像 phpinfo 中所述的 apc 文件.
Directory /tmp but I don't have any files of apc there like it's stated in phpinfo should occur.
请帮我检查 APC 是否正常工作,如果没有,可能是什么问题.
Please help me check if APC is working and if not, what can be a problem.
推荐答案
APC 可以两用方式:
- 作为操作码缓存.您启用了支持,所以这是有效的;和
- 作为一般缓存.为此,您必须明确使用 API.
(1) 是主要的好处.它通过存储编译"脚本的操作码结果来减少脚本执行的时间.
(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:
注意:在 Windows 上,APC 需要一个临时路径才能存在,并且可由网络服务器.它检查 TMP、TEMP、USERPROFILE 环境变量在该命令,最后尝试WINDOWS 目录,如果这些都不是设置.
Note: On Windows, APC needs a temp path to exist, and be writable by the web server. It checks TMP, TEMP, USERPROFILE environment variables in that order and finally tries the WINDOWS directory if none of those are set.
所以你不应该在 CentOS 上需要它(或查看任何活动).
So you shouldn't need it (or see any activity) on CentOS.
话虽如此,require/include 比 require_once/include_once/autoload 更好,但只有在处理数百个文件时才有意义.
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.
相关文章