简体   繁体   English

如何使APC(PHP缓存)工作?

[英]How to make APC (PHP Cache) work?

I've read about APC that it speeds up multiple php file sites. 我读过有关APC的信息,它可以加速多个php文件站点。 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. 所以我在PHP中有这个特殊的项目有很多文件,我发现require_once和解析只有类定义(不执行它们)需要花费大部分时间。

So I've installed APC on my CentOS 5 server. 所以我在我的CentOS 5服务器上安装了APC。 I moved apc.php to my webserver and it displays 我将apc.php移动到我的网络服务器并显示

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 ?? 我可以去网站和更改子页面,等等,apc.php仍然只显示一个缓存文件?

And in phpinfo() it shows that: 在phpinfo()中它表明:

APC Support enabled 启用APC支持

I don't know what to do. 我不知道该怎么办。 Is APC working (like phpinfo() sais) or is it not? APC是否正常工作(如phpinfo()sais)或不是吗? 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? 还有更多如何诊断错误并确保APC有效? I've browsed 我已经浏览过了

apc.mmap_file_mask /tmp/apc.QnLqNf /tmp/apc.QnLqNf 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. 目录/ tmp,但我没有apc的任何文件,就像在phpinfo中所说的那样。

Please help me check if APC is working and if not, what can be a problem. 请帮我检查APC是否正常工作,如果没有,可能会出现问题。

APC can be used in two ways: APC可以通过两种方式使用:

  1. As an opcode cache. 作为操作码缓存。 You have support enabled so this is working; 您已启用支持,因此这是有效的; and
  2. As a general cache. 作为一般缓存。 You have to explicitly use the API for this. 您必须为此明确使用API

(1) is the main benefit. (1)是主要的好处。 It reduces time for script execution by storing the opcode results of "compiling" scripts. 它通过存储“编译”脚本的操作码结果来减少脚本执行的时间。

As for it working, from the installation instructions : 至于它的工作原理,从安装说明

Note: On Windows, APC needs a temp path to exist, and be writable by the web server. 注意:在Windows上,APC需要存在临时路径,并且可由Web服务器写入。 It checks TMP, TEMP, USERPROFILE environment variables in that order and finally tries the WINDOWS directory if none of those are set. 它按顺序检查TMP,TEMP,USERPROFILE环境变量,如果没有设置,最后会尝试WINDOWS目录。

So you shouldn't need it (or see any activity) on CentOS. 所以你不应该在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. 话虽这么说,require / include比require_once / include_once / autoload更好,但只要你用数百个文件做这件事就应该这么做了。

Is your site basically one PHP file that then includes or requires other files? 您的网站基本上是一个PHP文件,然后包含或需要其他文件? 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! 另外,据我所知,条件包含/需要逻辑可能没有按预期缓存,虽然这可能只是传闻!

Did you check thr log files? 你检查了thr日志文件吗? take a look at /var/log/apache2/error.log or however its named under your distribution. 看一下/var/log/apache2/error.log,或者在你的发行版下命名它。

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.. 另外,尝试制作2-3个php文件,将浏览器指向它们,然后检查APC缓存缓存了多少个php文件。

Not sure about APC, but i'd recommend Eaccelerator ( http://eaccelerator.net/ ). 不确定APC,但我推荐Eaccelerator( http://eaccelerator.net/ )。 I've tested it some time ago and really made a difference. 我前段时间对它进行过测试,确实有所作为。

APC actually doesnt share cache between proceses. APC实际上并不在进程之间共享缓存。 Try to configure your PHP-Process to fork Childs and let the Master PHP-Process stay running. 尝试配置PHP-Process以分叉Childs并让Master PHP-Process保持运行。

See: How to share APC cache between several PHP processes when running under FastCGI? 请参阅: 如何在FastCGI下运行时在多个PHP进程之间共享APC缓存?

In the APC 3.1.5dev branch, a new option was introduced allowing you to disable the opcode cache. 在APC 3.1.5dev分支中, 引入了一个新选项,允许您禁用操作码缓存。 It appears to be turned off by default. 它似乎默认关闭。

Try adding this to your APC config file: 尝试将此添加到您的APC配置文件:

apc.enable_opcode_cache=1

http://www.litespeedtech.com/support/forum/showthread.php?t=3761 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. “APC与PHP suEXEC不兼容,因为每个PHP进程都将使用自己的缓存内存,而不是共享。

You should try eAccelerator + /dev/shm if you need to use PHP suEXEC." 如果你需要使用PHP suEXEC,你应该尝试使用eAccelerator + / dev / shm。“

well got same problem, it seems PHP suEXEC + APC is problem 很好的问题,似乎PHP suEXEC + APC是问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM