CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: mod_perl:
Browser waits for Perl script to exit before displaying prints

 



hem
User

Sep 6, 2012, 9:20 AM

Post #1 of 7 (34434 views)
Browser waits for Perl script to exit before displaying prints Can't Post

Hello

I am calling a perl script from a PHP server side script. In the Perl Script I have a bunch of prints and sleeps. Problem is that the browser waits for the Perl Script to complete to display the prints. The prints are intented to give the user a live status of whats going on. But browser waits till the script exits and then displays everything

I tried adding $|=1; but it did not help

I am using:
Perl:
This is perl, v5.8.8 built for i386-linux-thread-multi

Apache:
Server version: Apache/2.2.6 (Unix)


Linux:
Fedora release 8




Code
#!/usr/bin/perl  
use CGI qw(:standard);
$|=1;
my $r = CGI->new();
print header('text/html');
print start_html;
$|=1;
$r->print ("Processing ... <br>");
$|=1;
$r->print ("Processing TWO ... <br>");
foreach $i (1..2) {
sleep 10;
$r->print ("Item .. $i <br>");
}
$r->print ("DONE <br>");
print end_html;




FishMonger
Veteran / Moderator

Sep 6, 2012, 9:29 AM

Post #2 of 7 (34433 views)
Re: [hem] Browser waits for Perl script to exit before displaying prints [In reply to] Can't Post

You should always be using the strict and warnings pragmas in all of your Perl scripts.

You only need the first $|=1; statement to disable the buffering.

Since the buffering is already disabled in the Perl script, The problem is probably in the way you're calling the script from PHP and the buffering is occurring on that end.


hem
User

Sep 6, 2012, 10:14 AM

Post #3 of 7 (34428 views)
Re: [FishMonger] Browser waits for Perl script to exit before displaying prints [In reply to] Can't Post

Yes i always use strict and warnings . This is just a test code .

May be its Apache server?

on php side its a simple call:

Code
elseif (isset($_GET["reboot"])) 
{
$x = $_GET["reboot"];
$y = $_GET["ip"];
$Command = "perl /var/www/cgi-bin/PerlScript.cgi $x $y";
passthru($Command,$ret);
//echo $ret;
}



FishMonger
Veteran / Moderator

Sep 6, 2012, 10:43 AM

Post #4 of 7 (34423 views)
Re: [hem] Browser waits for Perl script to exit before displaying prints [In reply to] Can't Post

It's more likely that the passthru() function is buffering the output it receives.


hem
User

Sep 6, 2012, 7:54 PM

Post #5 of 7 (34391 views)
Re: [FishMonger] Browser waits for Perl script to exit before displaying prints [In reply to] Can't Post

I realize this might not be the right forum but do you happen to know how can I call the perl script from php to not buffer output.

Appreciate your help


FishMonger
Veteran / Moderator

Sep 7, 2012, 6:53 AM

Post #6 of 7 (34358 views)
Re: [hem] Browser waits for Perl script to exit before displaying prints [In reply to] Can't Post

I don't have a lot of experience with php. Personally, I hate it and only use it when required by my boss.

If you read the user comments on php.net about the passthru() function you'll find postings from others with the same problem. Their recommendation was to use popen() instead of passthru(). I have not tried it myself, but it's worth a shot.


hem
User

Sep 8, 2012, 12:18 PM

Post #7 of 7 (34335 views)
Re: [FishMonger] Browser waits for Perl script to exit before displaying prints [In reply to] Can't Post

I wll try to do some more digging on PHP

Will post a solution if i find one

Thanks for your time and looking into this

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives