Perrin Harkins wrote:
On Monday 23 May 2005 3:21 pm, Arshavir Grigorian wrote:

I have some code that takes a long time to execute. What I would like to
do is to display several real time status messages on the user's browser
as the work is being done (Started doing A ... Done, Started doing B ...
Done, etc). Then once the work is done, I would like to wipe the status
messages and display some results.


See Randal's columns on this subject:
http://www.stonehenge.com/merlyn/LinuxMag/col39.html
http://www.stonehenge.com/merlyn/WebTechniques/col20.html

- Perrin

Following Randal's examples, I wrote the following code which does not seem to work:

defined(my $childpid = fork()) or die "Cannot fork: $!";

if ($childpid) {

sleep 5;

$r->headers_out->set(Location => '/status/');

return Apache2::Const::REDIRECT;

} else {

open STDIN, "</dev/null";
    open STDOUT, ">/dev/null";

    my $object = Class->new();
    $object->generate_resultset();

    return Apache2::Const::OK;
}

[Tue Jun 14 14:23:24 2005] [error] Exception: DBD::Pg::st execute failed: lost synchronization with server: got message type " at Utils.pm line 38 - which is where I set the error handler on the DBI->connect().

When I eliminate the fork() call, and do everything in a pipeline mode, everything works fine so I know the code works. However for some other tasks that I am going to code, which take much longer than this one, I would like to have the option of processing in the background.

Thanks for any ideas.


--
Arshavir Grigorian
Systems Administrator/Engineer

Reply via email to