Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Preventing Browser Timeout

by Anonymous Monk
on Apr 23, 2003 at 20:37 UTC ( [id://252682]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I'm working on a CGI script. The user submits a very large quantity of text via a text box in a form. Once I get that data, I parse through it and extract from it a list of files that I need to create and the data that goes in them (some other processing on the data goes on as well). I write the files (printing a success/fail message after each), then put up another form. The problem is that there can be a *LOT* of data coming in from the user, and his browser may time out before I can parse out all the data and write the files.

What I'd like to do is either:
1.) Print a page that says something like "Processing, please wait...this page will refresh in five seconds." and have that page refresh until the file writing is done, then display the success/fail messages and the next form. Or if that can't be done,
2.) Print up the form and have the success/fail messages continually coming in and being displayed on the browser after it until it's done.

Any idea how this can be done? I imagine that I'd need to fork the processing off as one process and somehow keep tabs on it's progress or something.

Thanks!

Replies are listed 'Best First'.
•Re: Preventing Browser Timeout
by merlyn (Sage) on Apr 23, 2003 at 20:50 UTC
Re: Preventing Browser Timeout
by dws (Chancellor) on Apr 23, 2003 at 20:53 UTC
    Any idea how this can be done? I imagine that I'd need to fork the processing off as one process and somehow keep tabs on it's progress or something.

    merlyn has an article describing how to do the fork/keep-track-of trick.

    An alternative is to periodically send a "heart-beat" to the browser, to let it know that the CGI is still alive. A periodic

    print "<!-- working -->\n";
    is sufficient, provided you've disabled buffering. If you're processing multipe files, try doing this once per file.

    N.B., merlyn and I are pointing to different articles. Read both.

      Just to add to that, you can also just print " "; .

      -Lee

      "To be civilized is to deny one's nature."
        Just to add to that, you can also just print " "; .

        Sure, you can do that. The benefit of HTML comments as heartbeats is that they can also serve as diagnostic information. E.g., you can print timestamps in them, so get some feel for where your long-running program is spending time, and whether the heartbeats are too far apart (which risks a browser timeout).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-10-03 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (42 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.