Conditional Wait Time - PHP

Posted on 2007-08-07
Medium Priority
Last Modified: 2013-12-13
Currently I have the following piece of code:
exec("C:\MQInjector\MQexecuteBat.exe") or die("Error when running MQ Client");


$chgpwdo=fopen($fileread, "r") or die("Error - MQ Client did not complete run");
$read=fread($chgpwdo, filesize($fileread));

The exec statement creates the ChgPwd1.out file, therefore I have put the 2second wait in there to ensure the file is created. However, this is probably not the best way to do it.

Is it possible to structure this to ensure the file is created and current (Note that the exec command may also over-write an existing copy of the ChgPwd1.out file)?
Question by:doyle007
1 Comment
LVL 48

Accepted Solution

hernst42 earned 1000 total points
ID: 19651834
You can use the filemtime function like:


$curfiletime = @filemtime($fileread);
exec("C:\MQInjector\MQexecuteBat.exe") or die("Error when running MQ Client");
$i = 0;
while ($curfiletime == @filemtime($fileread)  && $i++<10) { sleep(2); clearstatcache(); }
if ($i == 10) { echo "file was not updated within 20seconds"; }

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question