Page 1 of 1

Ackward File Caching Situation

Posted: Thu Aug 23, 2007 6:08 pm
by apfritts
Hi,

I have designed a PHP page that continuously pings a file location to see if the file exists. Once it does, it returns the user's page. I was using the file_exists function (which I understand caches files that already exist, but do not cache information on files that do not exist) but that wasn't working. So I wrote function to try and read the file which returns true if it successfully opens the file and false if opening the file fails. This doesn't work either.

I know the file exists because I can read the file using a command line in Linux.

I am using the clearstatcache() function before, between and after the file_exists and fopen calls.

Has anyone ever run into this problem before or have any ideas how I could fix it? Here is some of my code:

While loop that waits for the file to exist:

Code: Select all

while (!file_exists("/dir/to/random/file")) {
	clearstatcache();
	sleep(1);
}
Function that returns true when the file is opened and false when it cannot open the file.

Code: Select all

function FileIsReadable($file) {
	if (!$fp = @fopen($file,"r")) {
		return false;
	}
	@fclose($fp);
	return true;
}