including just created file

From: Date: Fri, 26 Jul 2002 13:54:55 +0000
Subject: including just created file
Groups: php.general 
Request: Send a blank email to php-general+get-109726@lists.php.net to get a copy of this message
Hi all, I just coded a cache mechanism for some slow code that looks like this:
       $cache_file_name = "cache/$id/$tid". ($showall ? '_all.php' : '.php');
       $cache_dir_name= "cache/$id";
             if(!file_exists($cache_file_name) || @filectime($cache_file_name) + 30 < time() ) {
           if(!is_dir($cache_dir_name)) {
               mkdir($cache_dir_name, 0777);
           }
           $lock=@fopen($cache_file_name . '.lock','w');
           if(flock($lock,LOCK_EX)) {
               include('modules/rally_live/create_cache.php');
               flock($lock,LOCK_UN);
           }
           fclose($lock);
       }
       clearstatcache();
       for($i=0;!file_exists($cache_file_name);$i++) {
           if($i==3) die('<b>Cannot read cache file!</b>');
           clearstatcache();
       }
       include($cache_file_name);  // *sometimes includes empty file*
       echo "<!-- File $cache_file_name included -->";
The 'create_cache.php' creates a php code, that later needs to be executed. The problem is, the just created cache file seems to be empty *sometimes* when included, however, if I look at it, it does contain code. I do call fflush($cache_file) before closing it, so I don't see why the file is empty. If anyone can help me, I would be really glad.

« previous php.general (#109726) next »