Home > Archive > PERL CGI Beginners > December 2005 > browser does not show output from perl script when sleep is used
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
browser does not show output from perl script when sleep is used
|
|
| Neelay 2005-12-02, 9:04 pm |
| Hi all,
I have a simple Perl script, executing on a thttpd web server, which
looks like this-
#! /usr/bin/perl -w
use strict;
print "Content-type: text/html\n\n";
print <<HTML_BLOCK;
<head>
<title>Floodguard Configuration Management Tool</title>
</head>
<body>
<h4 align="center">Going to sleep now...</h4>
HTML_BLOCK
sleep($interval);
print <<HTML_BLOCK;
<h4 align="center">Is it morning already?!?</h4>
</body>
HTML_BLOCK
Now with $interval = 0, the script executes fine and the output is
displayed by the browser. However, as the value of $interval is
increased, the browser starts taking time to display the page until
eventually it does not load the page at all. For example, when
$interval = 50, the browser shows "loading" in status bar for sometime,
after which is simply reports "Done" and stops on the current page. Any
idea what could be causing this behaviour?
Help will be highly appreciated!
Thanks,
Neelay.
| |
| usenet@DavidFilmer.com 2005-12-02, 9:04 pm |
| Neelay wrote:
> Now with $interval = 0, the script executes fine and the output is
> displayed by the browser. However, as the value of $interval is
> increased, the browser starts taking time to display the page until
> eventually it does not load the page at all. For example, when
> $interval = 50, the browser shows "loading" in status bar for sometime,
> after which is simply reports "Done" and stops on the current page.
Suppose you had $interval = 500000000. Would you expect the webserver
to keep the connection open for that long?
Most webservers time out a connection if it is idle for too long (the
server assumes the process has hung or died). I'll bet that's what's
happening in your case. The webserver is closing the connection because
it think it's messed up.
If you have control over your webserver, you can override this value.
If you're using Apache, it would be the KeepAliveTimeout setting
(defaults to 15 seconds on my build).
| |
| Neelay 2005-12-02, 9:04 pm |
| I'm using thttpd; I also tried this on Apache, which gives a different
behaviour- it waits for the sleep interval and fetches the page all at
once, rather than fetching the first part, waiting and then fetching
the next. I also increased KeepAliveTimeout to 300 secs but Apache's
behaviour remains the same - display the entire page together after
waiting for sleep interval.
Is there support for content type multipart and flush in CGI Perl
scripting? I have control over the server; so I can either change
server parameters or change the perl script too.
Thanks.
-Neelay.
usenet@DavidFilmer.com wrote:
> Neelay wrote:
>
> Suppose you had $interval = 500000000. Would you expect the webserver
> to keep the connection open for that long?
>
> Most webservers time out a connection if it is idle for too long (the
> server assumes the process has hung or died). I'll bet that's what's
> happening in your case. The webserver is closing the connection because
> it think it's messed up.
>
> If you have control over your webserver, you can override this value.
> If you're using Apache, it would be the KeepAliveTimeout setting
> (defaults to 15 seconds on my build).
| |
| usenet@DavidFilmer.com 2005-12-02, 9:04 pm |
| Neelay wrote:[color=darkred]
You can print any sort of HTML header you want. Perl knows nothing
about "content type" (for that matter, Perl knows nothing about HTML),
nor does Perl care what you print (the browser, however, knows and
cares - very much).
[color=darkred]
You can force Perl to not buffer output (I think that's what you're
asking); put this near the top of your script (before any print
statements):
select STDOUT; $| = 1;
|
|
|
|
|