note 96621 added to function.clearstatcache

From: Date: Mon, 08 Mar 2010 19:54:16 +0000
Subject: note 96621 added to function.clearstatcache
Groups: php.notes 
Request: Send a blank email to php-notes+get-166798@lists.php.net to get a copy of this message
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); // is_dir($target) is now cached as true echo "Unlinking $target.\n"; rmdir($target) || die("Unable to unlink $target.\n"); // This will say "yes", which is old (inaccurate) information. report($target); if (($pid = pcntl_fork()) === -1) { die("Failed to pcntl_fork.\n"); } elseif ($pid === 0) { // child report($target, '<<child>> '); echo "<<child>> Clearing stat cache.\n"; clearstatcache(); report($target, '<<child>> '); } else { // parent sleep(2); // move this to the child block to reverse the test. report($target, '<<<parent>> '); clearstatcache(); report($target, '<<<parent>> '); } ?> ---- Server IP: 192.41.40.227 Probable Submitter: 168.122.66.50 ---- Manual Page -- http://www.php.net/manual/en/function.clearstatcache.php Edit -- https://master.php.net/note/edit/96621 Del: integrated -- https://master.php.net/note/delete/96621/integrated Del: useless -- https://master.php.net/note/delete/96621/useless Del: bad code -- https://master.php.net/note/delete/96621/bad+code Del: spam -- https://master.php.net/note/delete/96621/spam Del: non-english -- https://master.php.net/note/delete/96621/non-english Del: in docs -- https://master.php.net/note/delete/96621/in+docs Del: other reasons-- https://master.php.net/note/delete/96621 Reject -- https://master.php.net/note/reject/96621 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166798) next »