Page 1 of 1
Real time output from shell_exec() or similar
Posted: Tue Dec 02, 2008 1:35 am
by miro_igov
Hi guys,
does someone know is it possible to display data from shell_exec or similar function in real time.
Purpose is that if i have long process shell_exec will wait until process is complete before to return any results. This will lead to long load time of a web page. If it is possible to display parts of the output with flush() would be great, but i am not sure if php supports such thing.
Example could be `ping yahoo.com -c 1000 -s 32000`, this command will take much time to complete.
Re: Real time output from shell_exec() or similar
Posted: Sun Dec 07, 2008 3:46 am
by miro_igov
Anybody?
Re: Real time output from shell_exec() or similar
Posted: Sun Dec 07, 2008 5:02 am
by requinix
Most of those functions wait until the output stream ends, i.e. the program quits.
I think you'll have to open a pipe, run the command, and collect the output yourself. Try
popen; look at the second example.
Re: Real time output from shell_exec() or similar
Posted: Mon Feb 23, 2009 3:26 pm
by tomolas
Hi !
I'm solving the same problem here. Have you solved yours already ?
Maybe you can give me a little hint..
I am trying to create a progress bar of such long time taking process in javascript/ajax. So i need something to read data from pipe as it is being written line by line in real time. I'm good as soon as I have the content of that pipe in some variable not stuck in loop waiting for eof (end of file).
Does anybody have an idea ?
Re: Real time output from shell_exec() or similar
Posted: Mon Feb 23, 2009 4:02 pm
by requinix
Hey, I know the question may seem similar to yours but you should really create your own thread. Next time, okay?
If the process takes a long time to complete but steadily outputs information then you can use a pipe (
popen still) and then
flush the output to the browser immediately.
Code: Select all
while (reading from pipe) {
get line of data
echo data
flush
}
For a loading bar, unless you know the amount of data to be collected and you can actually measure progress, just print an animated gif at the top of the page and some JavaScript to hide it when the output is done.
Code: Select all
print loading gif
loop {
...
}
print javascript to hide image