--- .sync/CacheContent_005.php 2004-06-14 15:37:29.381041184 -0300 +++ CacheContent.php 2004-06-14 15:36:49.514101880 -0300 @@ -29,9 +29,16 @@ function CacheContent($name,$exclude=array(),$set_no_cache=false) { if (substr(APP_CACHE_DIR,-1)=='/') $this->cachefile=APP_CACHE_DIR.md5($name); else $this->cachefile=APP_CACHE_DIR.'/'.md5($name); + + $this->lockfile = $this->cachefile.'.lock'; if (isset($_GET['clearcache']) && file_exists($this->cachefile)) { - unlink($this->cachefile); + $lp = fopen($this->lockfile, 'w'); + if (flock($lp, LOCK_EX)) { + unlink($this->cachefile); + flock($lp, LOCK_UN); + } + fclose($lp); } $cache=true; @@ -45,8 +52,20 @@ function begin() { if ($this->cache && file_exists($this->cachefile)) { - readfile($this->cachefile); - return false; + $success = false; + $lp = fopen($this->lockfile, 'w'); + if (flock($lp, LOCK_SH)) { + readfile($this->cachefile); + flock($lp, LOCK_UN); + $success = true; + } + fclose($lp); + if ($success) { + return false; + } else { + ob_start(); + return true; + } } else { ob_start(); return true; @@ -55,12 +74,17 @@ function end() { if ($this->cache) { - $var=ob_get_contents(); - $fp=fopen($this->cachefile,'w'); - chmod($this->cachefile,0660); - fwrite($fp,$var); - fclose($fp); - + $var = ob_get_contents(); + $lp = fopen($this->lockfile, 'w'); + if (flock($lp, LOCK_EX)) { + $fp = fopen($this->cachefile, 'w'); + fwrite($fp, $var); + fclose($fp); + chmod($this->cachefile, 0660); + flock($lp, LOCK_UN); + } + fclose($lp); + chmod($this->lockfile, 0660); ob_end_flush(); } }