> $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 you may have loaded/altered the file system between calls to this directory/file, you need to use: http://php.net/clearstatcache > 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); What happens if I don't get the lock?... You just skip all this code... I think you need some kind of while() loop to just keep trying until you *DO* get a lock... Otherwise, you will sometimes blow right by here, read the file that the other script got a lock for, but hasn't created yet, and BAM!, there's your "sometimes empty" files that have the code in them when you go looking, because you have a race condition. > } > clearstatcache(); Hmmmm. Might be okay for this to be only here, but I'd copy it above as well. *EVERYWHERE* you might need *current* file info. > 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. I think it's just your locking mechanism isn't safe, as described above. You can probably get rid of the for loop now. -- Like Music? http://l-i-e.com/artists.htm I'm looking for a PRO QUALITY two-input sound card supported by Linux (any major distro). Need to record live events (mixed already) to stereo CD-quality. Soundcard Recommendations? Software to handle the recording? Don't need fancy mixer stuff. Zero (0) post-production time. Just raw PCM/WAV/AIFF 16+ bit, 44.1KHz, Stereo audio-to-disk. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php