Hi,
I would like to know if it is possible to execute a shell command via php and display the results of the command as they happen without refreshing the page (ie yum check-update)
Right now I only get the output after the command finishes.
Is it posssible?
If not, is there a way to show a message like "Checking updates..." and when the command finishes show the output?
Thanks
Display shell command results as they happen
I think you can do that by adding ob_start() to the top of your script, and then call ob_flush() at each point that you want something written to the browser. Note that if you are using HTML tables, only the parts of the table above this part of the script will be sent to the browser. The solution might be to use an iframe for the section of the page that's receiving the results (or simply not use tables). Then again, I'm not 100% sure the (partial) tables would cause a problem.
Thanks for the reply. I tried it but nothing happens. Any ideas?
Followup, certain issues with html rendering means that the browser agent may choose to delay rendering. Setting the output to something like plaintext or enclosing each line in paragraph tags usually works.
Thanks for the reply Sxooter, but I can't seem to get it right.
I am using the code below:
passthru("yum check-update",$var);
echo $var;
ob_implicit_flush(1);
but the result is outputed after the command ends. I am not sure if I am using the implicit_flush. I have never used it before.
I have also tried with exec() and putting the result into an array, which I loop, but still the same results.
Originally posted by tombell
Thanks for the reply Sxooter, but I can't seem to get it right.
I am using the code below:
passthru("yum check-update",$var); echo $var; ob_implicit_flush(1);
but the result is outputed after the command ends. I am not sure if I am using the implicit_flush. I have never used it before.
I have also tried with exec() and putting the result into an array, which I loop, but still the same results. [/B]
Got the order wrong:
<plaintext>
<?php
ob_implicit_flush(1);
passthru("somescript");
?>
Still nothing happens as it should.
Any other suggestions?
Thanks for your help
The comments here:
have a workaround for this issue. Not sure if it works or not.
I have read this but .....
Thanks anyway