I have many perl scripts running on linux, which goes and do many tasks, each one of them takes like 10 mins (taking backups and stuff like that..) and outputs the each step.. so that User sees what is the script is doing at that time...
What I am doing right now is calling perl script from php through shell_exec()
command,
what happens is that the output is shown after the script has finished the work and for that browser keep loading for 10 mins , which is not interactive.
So I want to get the output directly to browser from the perl sc开发者_高级运维ript as it is running, meaning as soon or may be after 2 secs whatever output is there from perl script I want to show it on my webpage..
I haven't tried this, but presumably, you should be able to open a pipe using popen to read the Perl script's output and echo to the browser.
Randal Schwartz's Watching long processes through CGI shows the implementation of a more sophisticated approach in Perl.
You can try passthru() which is a variation of exec that outputs any console output right away (or so I believe). Make sure no output buffering is enabled. Otherwise try proc_open and poll the file handle.
If that doesn't work, redirect the output of the Perl backup script to a temporary file, and poll it via AJAX/something to update the webpage.
Otherwise I'm unsure as to how we could help you speed up the 10 minute runtime into 2 secs.
精彩评论