Hi,
I'm doing a web app for a customer running an old UNIX system. The way I communicate with his system is to create a text file with a question. Then, the UNIX system answer me in milliseconds with another text file.
So, I think the obvious thing to do is to write the file and the loop while the response file is not created with a sleep between each loop.
However, even if I loop for a minute long, the file is never seen as existing although it exists. What's wrong?
Here's my code:
// This the question sent to the UNIX system
// Create a file, then the system reads it. This is OK.
$qst = "12345";
$file = "question.QST";
if (!$file_handle = fopen($file,"a")) { echo "Cannot create file"; }
if (!fwrite($file_handle, $qst)) { echo "Cannot write to file"; }
fclose($file_handle);
// Now we loop until we get the response
$fileResponse = "answer.RES";
$fh = false;
$tryCount = 0;
while (!file_exists($fileResponse) && $tryCount < 10)
{
usleep(10000); // Wait a little bit
$tryCount++;
}
The file is really created, but never catched by the file_exists function. I also tried to oepn the file with fopen, it still doesn't work.
The only way I got this thing to work is to sleep 1 second after the writing, before the reading.
Why the file_exists function doesn't catch the file? How could I do this faster?
Thanks for any idea
Stephane