1

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 script 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..

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sinan, popen approach is not working, havent tried the second one seems more complex to me at first look, but will look into.
0

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.

1 Comment

Mario, passthru() not working, nor proc_open as they tend to send the process to background; Well, I had the idea of using AJAX but I cannot direct output for 100 scripts; so that option is not there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.