Conditional Wait Time - PHP

Posted on 2007-08-07
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

    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

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now