APC works by storing the opcodes from PHP files in shared memory. When PHP is used with a web server (eg Apache) then the shared memory has a long life. When called from the commandline, then the APC cache is created and destroyed for each process. APC is disabled on the commadnline by default, probably due to this.
I have a theory that there will be benefits from using APC if a PHP process is forked (with pcntl_fork()
as presumably the same opcode cache can be used. This may only apply to files included after the fork.
What's the best way to benchmark this? Can anyone either test this or explain whether the theory is correct or not?
<?php
if (pcntl_fork()) {
// parent
include 'huge-file.php';
} else {
// child
sleep(1); // stop race condition
include 'huge-file.php'; // will this use APC's cache?
}