6

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:

apc.php

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
Community
  • 1
  • 1
BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

3

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.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • 1
    This might explain the apc.stat=0 behavior (http://www.php.net/manual/en/apc.configuration.php#ini.apc.stat): For included/required files this option applies as well, but note that for relative path includes (any path that doesn't start with / on Unix) APC has to check in order to uniquely identify the file. If you use absolute path includes APC can skip the stat and use that absolute path as the unique identifier for the file. – Joel Beckham May 17 '13 at 05:48
  • Indeed, although I'm sure that my paths are absolute right now, I can't be that sure they've always been in the past... This question is getting a bit old, I'd need to do some fresh testing! – BenMorel May 17 '13 at 16:23