Perl CGI with System Call in background doesnt return immediately

Perl CGI with System Call in background doesnt return immediately

Post by David Matus » Sat, 28 Jun 1997 04:00:00



Hi,

I am trying to run the following script:

#!/usr/local/bin/perl

system("sleep 61 &");
system("sleep 62 &");
print "Content-type: text/html\n\n";
print "<HTML><BODY>Hi there!</BODY></HTML>\n";

When I run the script (minus the cgi part) under UNIX, it returns control
immediately and completes.  I can then check to see that my processes are
in the background.  Perl is handling this ok, and that is the
functionality I would expect (and desire).

HOWEVER, when I run this as a cgi-bin script, the browser doesn't
relinquish control back until ALL of the background processes are
completed.  This is NOT what I need.

Is there any way around this?  I am running Apache 1.2 on an HP system
with Perl 5.003.  I have also tried running this on a Linux system, as
well as having tried the NCSA 1.5 server, and I have tried using Perl
version 5.000.  I am using Netscape 3, but I have tried using Lynx and
other browsers as well.

Any help would be greatly appreciated.

Thanks in advance,
--David

--
David Matusow
NASA / GSFC / FDD

 
 
 

Perl CGI with System Call in background doesnt return immediately

Post by Marc Slemk » Sat, 28 Jun 1997 04:00:00


Try changing it to:

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<HTML><BODY>Hi there!</BODY></HTML>\n";
close(stdout);
system("sleep 61 &");
system("sleep 62 &");

If you _need_ to do the system()s before you output the other stuff,
you will probably have to fork and close stdout in the child while
having the parent block until the child exits.


>Hi,
>I am trying to run the following script:
>#!/usr/local/bin/perl
>system("sleep 61 &");
>system("sleep 62 &");
>print "Content-type: text/html\n\n";
>print "<HTML><BODY>Hi there!</BODY></HTML>\n";
>When I run the script (minus the cgi part) under UNIX, it returns control
>immediately and completes.  I can then check to see that my processes are
>in the background.  Perl is handling this ok, and that is the
>functionality I would expect (and desire).
>HOWEVER, when I run this as a cgi-bin script, the browser doesn't
>relinquish control back until ALL of the background processes are
>completed.  This is NOT what I need.
>Is there any way around this?  I am running Apache 1.2 on an HP system
>with Perl 5.003.  I have also tried running this on a Linux system, as
>well as having tried the NCSA 1.5 server, and I have tried using Perl
>version 5.000.  I am using Netscape 3, but I have tried using Lynx and
>other browsers as well.
>Any help would be greatly appreciated.
>Thanks in advance,
>--David
>--
>David Matusow
>NASA / GSFC / FDD



 
 
 

Perl CGI with System Call in background doesnt return immediately

Post by ALASTAIR AITKEN CL » Tue, 01 Jul 1997 04:00:00



>Try changing it to:

>#!/usr/local/bin/perl
>print "Content-type: text/html\n\n";
>print "<HTML><BODY>Hi there!</BODY></HTML>\n";
>close(stdout);
>system("sleep 61 &");
>system("sleep 62 &");

Try also setting $| = 1; which, "forces a flush after every read or write on
the currently selected output channel".

Alastair.