Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Unexpected Output

by braveluxan (Initiate)
on Jul 12, 2002 at 20:21 UTC ( #181389=perlquestion: print w/replies, xml ) Need Help??

braveluxan has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monksters! I am trying to write a progress bar of sorts just to let the user know something is happening. I have the the following code that works fine AS LONG AS THIS SCRIPT IS CALLED DIRECTLY from the browser. Meaning if I type in the URL then the script will run and a "." will show up every second.

BUT, if I make this script the <form action=progress.cgi method=post> from another script then when there will be a 10 second pause and the ".........." string is written all at once!

What gives? Im running Apache 1.3.14 so nph is no longer and issue .. yes? Perl: 5.005_03 built for sun4-solaris

Thanks!

# # progress.cgi # $|=1; print "Content-Type: text/html\n\n"; for ($i=1;$i<=10;$i++) { print "."; select(undef,undef,undef,1); }

Replies are listed 'Best First'.
•Re: Unexpected Output
by merlyn (Sage) on Jul 12, 2002 at 20:46 UTC
    The response will probably vary even from one browser to the next. What you are doing is risky. You should use a client-pull meta-refresh solution to indicate progress, and even that isn't a universal solution.

    An example of "search in progress" strategies may be found in one of my older columns.

    -- Randal L. Schwartz, Perl hacker

Re: Unexpected Output
by tadman (Prior) on Jul 12, 2002 at 22:54 UTC
    For those that aren't familar, in Apache 1.2 and prior, you had to name your script "nph-process.cgi", with then 'nph-' part meaning 'Non-Parsed Headers'.

    In Apache 1.3, this seems to have changed. The following notice has been posted in the Apache 1.3 upgrade notes:
    Apache now provides an effectively unbuffered connection for CGI scripts. This means that data will be sent to the client as soon as the CGI pauses or stops output; previously, Apache would buffer the output up to a fixed buffer size before sending, which could result in the user viewing an empty page until the CGI finished or output a complete buffer. It is no longer necessary to use an "nph-" CGI to get unbuffered output. Given that most CGIs are written in a language that by default does buffering (e.g., perl) this shouldn't have a detrimental effect on performance.

    "nph-" CGIs, which formerly provided a direct socket to the client without any server post-processing, were not fully compatible with HTTP/1.1 or SSL support. As such they would have had to implement the transport details, such as encryption or chunking, in order to work properly in certain situations. Now, the only difference between nph and non-nph scripts is "non-parsed headers".
    For whatever reason, though, using Apache 1.3.26, I find I still have to name the script 'nph-process.cgi'. For good measure, I also did this:
    my $q = CGI->new(); print $q->header(-nph => 1);
Problem might be with browser behavior?
by BorgCopyeditor (Friar) on Jul 12, 2002 at 20:45 UTC

    Not an answer, just a guess and a method for finding out more:

    Maybe it's the browser's fault. I'm wondering whether the browser displays content differently depending on whether its HTTP method is GET or POST.

    You might be able to test whether your script is doing what you expect even under POST conditions by writing up a mini-"browser" script via LWP::Simple or maybe one of the IO:: or HTTP:: modules.

    Hope this helps,

    BCE
    --Your punctuation skills are insufficient!

Re: Unexpected Output
by tjh (Curate) on Jul 13, 2002 at 16:14 UTC
    So, it's probably a stupid question... but,

    browser -> script1.cgi -> progress.cgi and back right? Or did I read that wrong?

    script1 will wait for progress.cgi to complete before responding back to the browser? Is script1 set to $|=1 so it passes each response to the browser unbuffered also? And is it looping and printing rec'd progress.cgi output each time it receives it? Might be easiest to redesign to do it directly from the script called by the browser (modularize it?).

    0.02

      Clarification:

      If i type in "progress.cgi" directly into the browser (so it is called directly) then it runs as expected printing a "." every second for 10 seconds.

      =BUT=

      If i call progress.cgi from ANOTHER script via either POST or GET, then there is a 10 second pause and a sting of 10 periods is printed all at once: ".........." instead of 1 at a time.

      - Both scripts have $|=1 enabled (disabled?) :)
      - Same behaviour for both GET and POST methods
      - Same behaviour in both IE and Mozilla
      - I get the correct behavior if i call the script directly from a browser
      - I get the correct behavior if i telnet to the web server and do a manual GET

      TIA.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://181389]
Approved by dimmesdale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-12-07 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?