Page 1 of 1

PHP - system command - in the background

Posted: Fri Nov 24, 2006 7:20 am
by ianripping
Hi,

I have a PHP page that calls a python script from the command line using the PHP system command:

system($command);

The python script takes about 60 secs to run, I would like to display a 'Please Wait' message on the page whilst the script is running
Does anyone have any suggestions for the best way to do this?

Thanks

Re: PHP - system command - in the background

Posted: Fri Nov 24, 2006 7:45 am
by Chris Corbyn
ianripping wrote:Hi,

I have a PHP page that calls a python script from the command line using the PHP system command:

system($command);

The python script takes about 60 secs to run, I would like to display a 'Please Wait' message on the page whilst the script is running
Does anyone have any suggestions for the best way to do this?

Thanks
Execute it using AJAX so it's asyncronous. Or just use output buffering to flush the message to the screen. The browser will hang though without ajax.

Posted: Fri Nov 24, 2006 8:00 am
by ianripping
Could you give me an example of how to use AJAX in this context?

Posted: Fri Nov 24, 2006 8:00 am
by impulse()
Why wouldn't this work:

Code: Select all

echo "Please wait";
system("python script.ph");

Posted: Fri Nov 24, 2006 8:03 am
by ianripping
The browser not display anything until the command has been executed and has returned an exit code - it will then display the echo line.

This is my problem - I want to see the echo line first - then the process executes.
Then when the exit code is returned - I want to redirect to another page.

Posted: Fri Nov 24, 2006 8:08 am
by ianripping
I could use exec('start /B "command',$output,$return);

but this will not tell me when the command has finished executing - which I need to know before redirecting to another page where another script will be executed!

Posted: Fri Nov 24, 2006 8:19 am
by impulse()

Code: Select all

echo "Please wait";
system("python script.py");
header("Location: http://redirect.com");
That should work, I think

Posted: Thu Nov 30, 2006 10:27 am
by ianripping
My solution:

system ('start /low

Code: Select all

')

Posted: Thu Nov 30, 2006 12:28 pm
by ok
AJAX, as said before. You can read about it at: http://developer.mozilla.org/en/docs/AJAX.

Basically, you need to open your PHP page and each time tell PHP to execute another program (exec.php?prog=1, exec.php?prog=2 etc...).
When PHP is done, print (with PHP) message that indicates whether the execute did well or not - AJAX will display it to the user.

In my opinion, Java is the best language to execute programs (it gives more control...).