I run into a very weird situation with file_exists function. The hosting company said their php was configured in CGI mode instead of PHP mode. below is the code. It checks the existence of the file called test.txt in data folder on the fly during 50 seconds or so when loading the page containing the code. If file found, display "File exists" and exits the while loop. If no file found in 50 seconds, display "File does not exist" and breaks the loop too finishing loading the page.
Strange thing 1: it was not working as expected, can find the file only first time loading the page when file is there. It continues displaying "File exists" even after test.txt got removed when I refresh the page. If test.txt is not in the data folder at all, it displays "file not exists" even after I move back test.txt in the folder.
Strange thing 2: If I put a bigger file say over 170K in size, it looks working well, small files not though, especially under 40 bytes. I have tried many different ways to check file existence including absolute path, still no luck.
Thanks for any clue!
loading page...
$counter= 1;
while ($counter++) {
sleep(5);
if (file_exists("data/test.txt")) {
echo "File exists";
break;
}
if ($counter>10){
echo "File does not exist";
break;
}
}