Index: file.php =================================================================== RCS file: /repository/pear/Cache/Container/file.php,v retrieving revision 1.7 diff -u -u -r1.7 file.php --- file.php 23 May 2002 14:16:32 -0000 1.7 +++ file.php 30 May 2002 14:20:57 -0000 @@ -107,6 +107,9 @@ if (!($fh = @fopen($file, 'rb'))) return new Cache_Error("Can't access cache file '$file'. Check access rights and path.", __FILE__, __LINE__); + // File locking (shared lock) + flock($fh, LOCK_SH); + // file format: // 1st line: expiration date // 2nd line: user data @@ -114,13 +117,17 @@ $expire = trim(fgets($fh, 12)); $userdata = trim(fgets($fh, 257)); $cachedata = $this->decode(fread($fh, filesize($file))); + + // Unlocking + flock($fh, LOCK_UN); + fclose($fh); // last usage date used by the gc - maxlifetime // touch without second param produced stupid entries... touch($file,time()); clearstatcache(); - + return array($expire, $cachedata, $userdata); } // end func fetch @@ -137,6 +144,9 @@ if (!($fh = @fopen($file, 'wb'))) return new Cache_Error("Can't access '$file' to store cache data. Check access rights and path.", __FILE__, __LINE__); + // File locking (exclusive lock) + flock($fh, LOCK_EX); + // file format: // 1st line: expiration date // 2nd line: user data @@ -145,6 +155,9 @@ fwrite($fh, $expires . "\n"); fwrite($fh, $userdata . "\n"); fwrite($fh, $this->encode($cachedata)); + + // File unlocking + flock($fh, LOCK_UN); fclose($fh);