[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] teardown method


Quoting Mark Fuller <suppressed>:
> For session tracking, I keep the values in a hash and update the table in
> the "teardown" method. I thought this would be a faster way to update the
> session-tracking table because, by then, I the runmode would have emitted
> its output and the visitor would be receiving the page while the teardown
> method was updating the session-tracking table.
> 
> To test my assumption, I put a 10 second sleep in "teardown" and the page
> was delayed 10 seconds. Why does it work this way? Is this the server? Does
> it expect the executing CGI to end before it transmits output?

The connection to the browser is not closed until the CGI script finishes
executing.  Also, perl (and possibly the webserver) will buffer the page and
send it in chunks for performance reasons.

To get perl to flush it's buffers immediately you need to set the $| variable to
a nonzero value.  That will trigger perl to flush it's buffer after every print.
 See the man page for perlvar for more info.

sub teardown {
  $self = shift;
  local $| = 1;  # turn off buffering
  print "\n";    # force a flush
}

> I was hoping to get a little parallel processing. :)

If you are using mod_perl, you can truely do this processing after the
connection to the browser is closed.  mod_perl allows you to hook into the
logging or cleanup phase of Apache which occur after the connection is closed. 
This is probably overkill for writing a session to the DB, but can be very
useful for long running processes.

Cheers,

Cees

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.