On Linux, a forked process inherits a copy of the parent's cache, but after forking the two caches do not impact each other. The snippet below demonstrates this by creating a child and confirming outdated (cached) information, then clearing the cache, and getting new information.
<?php
function report($directory, $prefix = '') { printf('%sDoes %s exist? PHP says "%s"'. PHP_EOL, $prefix, $directory, is_dir($directory) ? 'yes' : 'no'); }
$target = './delete-me-before-running-statcache';
if (is_dir($target)) {
die("Delete $target before running.\n");
}
echo "Creating $target.\n";
mkdir($target) || die("Unable to create $target.\n");
report($target); echo "Unlinking $target.\n";
rmdir($target) || die("Unable to unlink $target.\n");
report($target);
if (($pid = pcntl_fork()) === -1) { die("Failed to pcntl_fork.\n"); }
elseif ($pid === 0) {
report($target, '<<child>> ');
echo "<<child>> Clearing stat cache.\n";
clearstatcache();
report($target, '<<child>> ');
} else {
sleep(2); report($target, '<<<parent>> ');
clearstatcache();
report($target, '<<<parent>> ');
}
?>