APC无法加快PHP 5.4的速度 [英] APC not speeding up PHP 5.4

查看:32
本文介绍了APC无法加快PHP 5.4的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前在WAMP Server和PHP 5.3上曾遇到过此问题,现在在带有PHP 5.4的Linux上都遇到过.

I have had this problem before on WAMP Server and PHP 5.3, and now facing it on Linux with PHP 5.4.

基本上,启用或禁用APC不会对性能造成任何影响,尽管apc.php中的统计数据如此.

Basically, APC enabled or disabled makes no difference in performance, despite what the stats in apc.php say.

这是一个示例测试脚本,其中包括30多个Doctrine PHP文件并对其进行计时:

Here is a sample test script, which includes more than 30 Doctrine PHP files, and times it:

$t = microtime(true);
include 'Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
printf('%.3f s', microtime(true)-$t);

  • Windows上的结果( Zend Server CE,PHP 5.4 ):0.001 s
  • Linux上的结果( PHP 5.4& APC 3.1.11 ):0.106 s
    • Result on Windows (Zend Server CE, PHP 5.4) : 0.001 s
    • Result on Linux (PHP 5.4 & APC 3.1.11) : 0.106 s
    • 注意:即使以上脚本中未显示,我实际上仍在使用文件的完整路径,而不依赖于include_path.

      无论apc.enabled0还是1,我在Linux上获得的结果都是相同的,因此看来操作码缓存不起作用.

      The result I get on Linux is the same whether apc.enabled is 0 or 1, so it looks like the opcode caching is just not working.

      但是,apc.php说:

      软件包(来自 remi存储库,CentOS 6.3):

      Packages (from the remi repository, CentOS 6.3):

      php-5.4.5-1.el6.remi.x86_64
      php-pecl-apc-3.1.11-1.el6.remi.1.x86_64
      

      APC配置:

      apc.enabled=1 
      apc.shm_segments=1
      apc.shm_size=64M
      apc.num_files_hint=1024
      apc.user_entries_hint=4096
      apc.ttl=7200
      apc.use_request_time=1
      apc.user_ttl=7200
      apc.gc_ttl=3600
      apc.cache_by_default=1
      apc.file_update_protection=2
      apc.enable_cli=1
      apc.max_file_size=1M
      apc.stat=1
      apc.stat_ctime=0
      apc.canonicalize=0
      apc.write_lock=1
      

      最后,,PHP确实将APC报告为已启用:

      Last thing, yes, PHP does report APC as enabled:

      var_dump(extension_loaded('apc')); // (bool) true
      

      推荐答案

      我忘了提到问题的重要部分:Web服务器在Windows 7下的linux虚拟机上运行,​​并且正在从共享库中读取文件.主机上的文件夹.

      I forgot to mention an important part of the problem: the web server is running on a linux virtual machine under Windows 7, and is reading the files from a shared folder on the host.

      我注意到,使APC变慢的原因是必须stat共享文件夹中的文件.

      I noticed that what slows down APC, is having to stat the files on this shared folder.

      将文件复制到虚拟机即可解决此问题.

      Copying the files to the virtual machine fixes the problem.

      但是,我很惊讶apc.stat=0不能单独解决问题,我本来希望它仅一次stat个文件,然后无条件地从内存缓存中读取所有内容.

      I'm however surprised that apc.stat=0 does not fix the problem alone, I would have expected it to stat the files just once, and unconditionally read everything from the in-memory cache afterwards.

      这篇关于APC无法加快PHP 5.4的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆