in reply to Long CGI process is cut short by browser

The basic approach for this sort of thing is the same as with threads, but you fork a process instead. A full example is here.
  • Comment on Re: Long CGI process is cut short by browser

Replies are listed 'Best First'.
Re^2: Long CGI process is cut short by browser
by C_T (Scribe) on Dec 02, 2004 at 23:11 UTC
    Ok, you're my hero!

    MANY THANKS!

    CT

    Charles Thomas
    Madison, WI
Re^2: Long CGI process is cut short by browser
by C_T (Scribe) on Dec 07, 2004 at 00:37 UTC
    This example by Randal helped me figure out how to keep the process alive.

    Perhaps you guys can solve the other part of the equation. Right now I'm doing something like this:

    #===== Open I/O pipes and run the process $pid = open3(\*DEV_NULL, \*OUT, \*ERR, "my_long_process"); #===== Print the results while (<OUT>) { $buffer .= $_; #===== Update the display cache $cache->set($session, [0, $buffer]); }

    Which works, except it waits until my_long_process completes before it sends any output back to the browser. If my_long_process takes an hour to run, the browser sits there for an hour with no updated information.

    Is there a way to set open3() to an unbuffered mode so it returns what my_long_process is doing in real time?

    Failing that, is there a better way to do this long process in the fork such that I can get its results as its doing things rather than waiting until the end?

    Thanks!

    CT

    Charles Thomas
    Madison, WI