Click here to get back home

Perl CGI Issue

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Perl CGI Issue Eric 06-06-2008
Posted by Eric on June 6, 2008, 3:53 pm
Please log in for more thread options
Hello,

I'm having an issue with a perl CGI script. The code looks like this:

#!/usr/bin/perl
use CGI;
use IO::Handle;

$|=1;

[... snip ...]

# Redirect the user to the appropriate output page.
$io = new IO::Handle;
if ($io->fdopen(fileno(STDOUT),"w")) {
$io->print("Output:output.php?load=$sum/$pdbid.html\n");
$io->flush() || die $!;
}

system("cmd & perl backend.pl $pdbid $sum"); # takes about 4
minutes to run

My web page makes an AJAX post to this cgi script to start the
"backend" process. Since that process takes a few minutes, I would
like the user to be taken to a waiting page. However, I need to pass
that $sum variable back to the page.

In my head, this code should print the output message to stdout, start
the backend.pl script in the background, exit and then send the
contents of stdout down to the web page.

In actuality what happens is there is a delay of several minutes
before the output message is sent to the page. However, it is not the
full amount of time required to run backend.pl. It seems to be pretty
consistently about half of the required time. The page then gets the
output message, and redirects to the waiting page and works fine from
thereon out.

Does anyone know how I can get that output message to my webpage
immediately? As you can see I've tried flushing stdout several
different ways with no luck.

Also, if there is a better group for me to post to, that would be
appreciated too.

Thanks,
Eric

Posted by A. Sinan Unur on June 6, 2008, 4:05 pm
Please log in for more thread options
@k37g2000hsf.googlegroups.com:

> if ($io->fdopen(fileno(STDOUT),"w")) {
> $io->print("Output:output.php?load=$sum/$pdbid.html\n");
> $io->flush() || die $!;
> }

...

> Also, if there is a better group for me to post to, that would be
> appreciated too.

I will recommend the main page at http://thedailywtf.com/

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by A. Sinan Unur on June 6, 2008, 4:23 pm
Please log in for more thread options

> news:ec87562b-c320-46a8-9ac9-4c2218e19599
> @k37g2000hsf.googlegroups.com:
>
>> if ($io->fdopen(fileno(STDOUT),"w")) {
>> $io->print("Output:output.php?load=$sum/$pdbid.html\n");
>> $io->flush() || die $!;
>> }
>
> ...
>
>> Also, if there is a better group for me to post to, that would be
>> appreciated too.
>
> I will recommend the main page at http://thedailywtf.com/

I am afraid everyone is going to get on my case for being rude again, so
let me ask you to please kindly explain what you are doing.

In general, the way to print to STDOUT in Perl is to

print "Output:output.php?load=$sum/$pdbid.html\n";

Sometimes you might have to explicitly specify the filehandle:

print STDOUT "Output:output.php?load=$sum/$pdbid.html\n";

The Perl only code you present in your post (well, OK, there is call to
system) is what I have quoted above. I am baffled as to what you think
this does and why you think you need it.

On the other hand, my powers of mental-telemetapathy tell me that you
might be interested in

http://www.stonehenge.com/merlyn/LinuxMag/col39.html

On the other hand, that may not be as webtwomoey and ajaxamahahey for
you.

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by Eric on June 6, 2008, 4:46 pm
Please log in for more thread options
>
> > news:ec87562b-c320-46a8-9ac9-4c2218e19599
> > @k37g2000hsf.googlegroups.com:
>
> >> if ($io->fdopen(fileno(STDOUT),"w")) {
> >> $io->print("Output:output.php?load=$sum/$pdbid.html\n");
> >> $io->flush() || die $!;
> >> }
>
> > ...
>
> >> Also, if there is a better group for me to post to, that would be
> >> appreciated too.
>
> > I will recommend the main page athttp://thedailywtf.com/
>
> I am afraid everyone is going to get on my case for being rude again, so
> let me ask you to please kindly explain what you are doing.
>
> In general, the way to print to STDOUT in Perl is to
>
> print "Output:output.php?load=$sum/$pdbid.html\n";
>
> Sometimes you might have to explicitly specify the filehandle:
>
> print STDOUT "Output:output.php?load=$sum/$pdbid.html\n";
>
> The Perl only code you present in your post (well, OK, there is call to
> system) is what I have quoted above. I am baffled as to what you think
> this does and why you think you need it.
>
> On the other hand, my powers of mental-telemetapathy tell me that you
> might be interested in
>
> http://www.stonehenge.com/merlyn/LinuxMag/col39.html
>
> On the other hand, that may not be as webtwomoey and ajaxamahahey for
> you.
>
> Sinan
>
> --
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpmisc/

Thanks for responding. I'm actually very new to both perl and cgi
scripting, so I really appreciate your kind and professional attidute.

Initially that line looked like this:
print "Output:output.php?load=$sum/$pdbid.html\n"

However, that message was not sent to the page in as timely a fashion
as I would like, so I tried setting autoflush. Still no go, so I
found that you can manually flush a buffer if you use that module. I
left it in both that line and the autoflush above it the hopes that it
would give you some idea of what I've already tried.

The "Output:" is simply a keyword that the page looks for when
deciding what to do with a message from the message from the cgi page.

Thanks,
Eric

Posted by Dan Rumney on June 6, 2008, 4:32 pm
Please log in for more thread options
A. Sinan Unur wrote:
> @k37g2000hsf.googlegroups.com:
>
>> if ($io->fdopen(fileno(STDOUT),"w")) {
>> $io->print("Output:output.php?load=$sum/$pdbid.html\n");
>> $io->flush() || die $!;
>> }
>
> ...
>
>> Also, if there is a better group for me to post to, that would be
>> appreciated too.
>
> I will recommend the main page at http://thedailywtf.com/

I believe this is a rather unhelpful way of indicating that that's some
very convoluted code to write to STDOUT.

use IO::Handle;
STDOUT->autoflush(1);
print "Output:output.php?load=$sum/$pdbid.html\n";

would suffice

Or maybe the confusion is about your use of "Output:"
That's not an HTTP header that I'm aware of. If you're trying to
redirect a User Agent, "Location:" would be the appropriate header

Similar ThreadsPosted
Perl performance issue July 27, 2005, 8:47 pm
perl array issue October 26, 2005, 7:47 pm
ASP.Net App Issue... Maybe Resolved via PERL? June 8, 2007, 2:47 pm
Perl LWP Issue with JSP's April 16, 2008, 2:29 pm
Perl User Name/Password issue April 1, 2005, 2:09 am
perl MySQL using DBI - security issue April 12, 2006, 4:24 am
DB Module installation issue in Perl April 21, 2007, 7:28 pm
A perl issue when execute system call July 19, 2007, 7:42 am
The Perl Review, Spring 2006: The Sudoku Issue February 28, 2006, 2:34 pm
Curl/Perl http post performanc issue August 2, 2006, 10:43 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap