PHP File include error -
i have following code in php page. times when delete cache2.html file, expect php recreate , next person cache2.html instead of executing php code. following warning times on page , no content. because of multiple users accessing php concurrently? if so, how fix it? thank you.
warning: include(dir1/cache2.html) [function.include]: failed open stream: no such file or directory in /home/content/54/site/index.php on line 8
<?php if (substr_count($_server['http_accept_encoding'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); $cachefile = "dir1/cache2.html"; if (file_exists($cachefile)) { include($cachefile); // output contents of cache file } else { /* html (built using php/mysql) */ $cachefile = "dir1/cache2.html"; $fp = fopen($cachefile, 'w'); fwrite($fp, ob_get_contents()); fclose($fp); ob_flush(); // send output browser } ?>
calls file_exists() cached, it's you're getting return value of true after file deleted. see:
http://us.php.net/manual/en/function.clearstatcache.php
so, do:
clearstatcache(); if (file_exists($cache)) { include($cache); } else { // generate page } alternatively, this:
if (file_exists($cache) && @include($cache)) { exit; } else { // generate page } or better, if you're deleting cache file within php process, call clearstatcache() after delete file.
Comments
Post a Comment