0

I'm have a long-running perl script that outputs the percentage complete. How do I show the completion status real-time on a php page?

Example:

perl:

my $i = 0;
for $i (1 .. 6) {
    print "$i\n";
    sleep 1;
}
print "script end\n";
exit;

php:

echo passthru('perl testprint.pl');

This works to display the output, but not real-time.

5
  • 1
    How does it output? A new percentage on each line? Backspacing over the old percentage with the idea that it would never be parsed? Commented Feb 23, 2012 at 20:01
  • The perl script currently outputs a new percentage on each line. However I can rewrite it if necessary. Commented Feb 23, 2012 at 20:03
  • convert the perl to php. ever one knows php is better :-) Commented Feb 23, 2012 at 20:08
  • "better" for what, though? ;) Commented Feb 23, 2012 at 20:10
  • 1
    clearly for monitoring or you would just use perl for both. Commented Feb 23, 2012 at 20:13

2 Answers 2

1

Modify your perl script to pipe the output to a flat file. Use a php script to parse this file and output in whatever format you want.

You could call the php script from your html page using ajax, or if you save the perl script in the server's CGI directory you can call it directly without the need for the extra php file.

Lastly, create a nifty progress bar and profit.

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

2 Comments

I think you're pointing me in the right direction. But would proc_open be of better use here?
I'm not familiar with that function but it seems like it could be dangerous if executed on a publicly accessible site or on a shared hosting server. maybe update your question with that suggestion and someone else more knowledgeable can chime in?
0

For that you need to utilize AJAX.

I would have a PHP script that looks at the status, and then have AJAX update the status for the user to see.

2 Comments

Ok, but how do I monitor the status without re-executing the script?
In that case you need the Perl script to create a socket to the browser and keeping the connection open for further updates. PHP does not have the ability to do this without hogging the servers resources.

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.