Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP command line, echo, & exec

Status
Not open for further replies.

raphael75

Programmer
Nov 15, 2012
67
US
I have a PHP script running on the command line on Apache/Windows. It calls exec() to run an external program (dbisql). While it's waiting for the program to finish running, which could be from 1 second to 10 minutes, I am trying to have it output something to indicate that it's still "alive". I know you can do this to have PHP echo text on the same line:

PHP:
<?php
    echo "Starting Iteration" . "\n\r";
    for ($i=0;$i<10000;$i++) {
        echo "\r" . $i;
    }
    echo "Ending Iteration" . "\n\r";
?>

But it seems that while the external program in executing PHP is "frozen" and can't do anything while it waits for the program to finish. Is there some way I can have it echo out something while it waits for the external program to finish?

Thanks!
 
Figured out a way around it. I used this:

PHP:
$wshshell = new COM("WScript.Shell");
$xexec = $wshshell->Run($cmd, 0, false);

to start the command and then below is a while loop that scans for the presence of a file the dbisql generates. That fixed it.
 
There are process forking functions that are native in php.
 
Per oracledba.help, to get unbuffered, i.e. real-time output to the console use STDOUT not echo or print.

Example:
PHP:
fwrite(STDOUT,"Hello World! \n");


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top