APC not speeding up PHP 5.4

2019-04-29 02:58发布

问题:

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

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

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);
  • 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

Note: even if not displayed in the above script, I'm actually using a full path to the file, and not relying on the include_path.

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.

However, apc.php says:

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 configuration:

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

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

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

回答1:

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.

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.

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.



标签: php apc