Re: Perl:CGI - Creating a Please wait message



On Feb 16, 11:36 am, "Petr Vileta" <sto...@xxxxxxxxxxxxx> wrote:
<wjharris...@xxxxxxxxxxxxx> píse v diskusním príspevkunews:1171642388.838134.117810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I have created a CGI program which dynamically creates an HTML FORM.
This form upon submit, goes out and does some work that can take up to
10 minutes to complete. Once done, the called CGI provides the user
with logged results.

My goal is to provide the user with an automated GIF and a message to
please stand by while the program is out doing its work.

I have tried to first display this "Please wait ... processing your
transaction" message at the beginning of the called CGI called
program, before any work is done. I have also tried to call an
intermediary CGI program which displays the message and calls the
working CGI in the background.

In all cases, the message is not displayed until after the CGI working
program [which takes 10 minutes to complete] has actually completed!

Try to put
$| = 1; // switch to unbuffered output mode
at the begin of your script.
Many browser used to don't display content until receive needed bytes from
server. A little trick is to send to browser some spaces (0x20 character).
Browser must receive these spaces but show only one.

Example:

use strict;
$| = 1;
print "Content-type: text/html\n\n<head><body>\n<p>Please wait ...
processing your transaction";
my $time = 0;
while($time < 30)
{
print ' 'x1024;
sleep 2; # or do something other
$time++;
}
print " <b> - Done</b></body></html>\n";

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

=============================================================================
I really appreciate your prompt reply! I have tried your suggestion
and flush does not occur until after the program completes. I tried
this
on the command line and it works like a charm however within the
browser it
does not. Any other suggestions?

$|
$OUTPUT_AUTOFLUSH
autoflush HANDLE EXPR
If set to nonzero, forces an fflush(3) after every write or print on
the currently selected output channel. (This is called "command
buffering". Contrary to popular belief, setting this variable does not
turn off buffering.) Default is 0, which on many systems means that
STDOUT will default to being line buffered if output is to the
terminal, and block buffered otherwise. Setting this variable is
useful primarily when you are outputting to a pipe, such as when you
are running a Perl script under rsh and want to see the output as it's
happening. This has no effect on input buffering. If you have a need
to flush a buffer immediately after setting $|, you may simply print
""; rather than waiting for the next print to flush it. (Mnemonic:
when you want your pipes to be piping hot.)

Thanks,
Bill

.



Relevant Pages

  • Re: re-posting: web.py, incomplete
    ... sorry first of all for my adding to the confusion when i jumped to ... python cgi scripts in the buffered mode will either result in ... since apache itself does no buffering of cgi output, ...
    (comp.lang.python)
  • Re: How to send a key event to another process?
    ... Browser sends a GET or POST HTTP request to web server ... Web server decodes GET/POST URL and determines which CGI program to call ...
    (comp.os.linux.misc)
  • Re: CGI, PATH_INFO, convenience/security (TXT or HTML? -- IE NEW BUG)
    ... yet normal PDF files are handled ... By configuring an alias for the cgi program with a PDF ... the PATH_INFO slot to fool the browser. ...
    (Bugtraq)
  • Re: Trying to read xml output from Acrobat form
    ... > I've made a little form in Acrobat 7.0 Professional with a submit ... Check to make sure the complete URL of your script is in the submit action. ... I'd suggest you set up Firefox as your browser, ... > I have a little cgi set up on my personal server: ...
    (comp.lang.perl.misc)
  • Re: CGI and checkboxes
    ... You might want to invest in an introductory book on CGI programming. ... Browser sends request to some web server for some page. ...
    (comp.lang.ruby)