long background tasks

2001-01-25 Thread Louis-David Mitterrand

Hello,

Were are trying to run long a task (DB import) from a HTML::Mason page
and are trying to send an immediate response to the user while the task
is running. Here is our pseudo-code:

%init
sub long_running_task {
# lottsa long, boring stuff
}
$r-puch_handlers(PerlCleanupHandler=\long_running_task($myarg));
/%init

The rest of the page sends back HTML. The problem is that it _not_ sent
back until the long_running_task function has completed.

I thought that when registering a code ref in that way the sub{} would
not be called until later during the PerlCleanupHandler phase.

Am I missing something, is there a better way to do it?

Thanks in advance for your insight,

-- 
 HIPPOLYTE: Quelques crimes toujours précèdent les grands crimes.
Quiconque a pu franchir les bornes légitimes
Peut violer enfin les droits les plus sacrés ;
  (Phèdre, J-B Racine, acte 4, scène 2)



Re: long background tasks

2001-01-25 Thread Matt Sergeant

On Thu, 25 Jan 2001, Louis-David Mitterrand wrote:

 Hello,

 Were are trying to run long a task (DB import) from a HTML::Mason page
 and are trying to send an immediate response to the user while the task
 is running. Here is our pseudo-code:

 %init
 sub long_running_task {
   # lottsa long, boring stuff
 }
 $r-puch_handlers(PerlCleanupHandler=\long_running_task($myarg));
 /%init

 The rest of the page sends back HTML. The problem is that it _not_ sent
 back until the long_running_task function has completed.

 I thought that when registering a code ref in that way the sub{} would
 not be called until later during the PerlCleanupHandler phase.

 Am I missing something, is there a better way to do it?

Send out Content-Length so your browser knows the content is finished.

Also you might want to check out
http://take23.org/docs/guide/performance.xml/4#4.3

-- 
Matt/

/||** Director and CTO **
   //||**  AxKit.com Ltd   **  ** XML Application Serving **
  // ||** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // ** Personal Web Site: http://sergeant.org/ **
 \\//
 //\\
//  \\




Re: long background tasks

2001-01-25 Thread Paul


--- Louis-David Mitterrand [EMAIL PROTECTED] wrote:
 Hello,
 
 Were are trying to run long a task (DB import) from a HTML::Mason
 page and are trying to send an immediate response to the user while
 the task is running. Here is our pseudo-code:
 
 %init
 sub long_running_task {
   # lottsa long, boring stuff
 }
 $r-puch_handlers(PerlCleanupHandler=\long_running_task($myarg));
 /%init

 The rest of the page sends back HTML. The problem is that it _not_
 sent back until the long_running_task function has completed.
 
 I thought that when registering a code ref in that way the sub{}
 would not be called until later during the PerlCleanupHandler phase.
 
 Am I missing something, is there a better way to do it?
 
 Thanks in advance for your insight,

Since you're pushing that handler onto the cleanup phase, I'm assuming
that you don't mean to send any more data to the client. It sounds like
the buffer isn't getting flushed (though I can't imagine why). Maybe if
you flush it manually? "local $|=1" or something?

I've had this problem in cases where I wanted to fork a long running
subprocess, because the child's STDIN and STDOUT are still pegged to
the browser socket. For a child, it works pretty well to close and
reopen the STD' filehandles to dissociate from the client after the
fork (like running a daemon).

Would that do for what you need here?
 
 -- 
  HIPPOLYTE: Quelques crimes toujours précèdent les grands crimes.
 Quiconque a pu franchir les bornes légitimes
 Peut violer enfin les droits les plus sacrés ;
   (Phèdre, J-B Racine, acte
 4, scène 2)

...since I don't have a copy of Phaedra on my desk, would you translate
this for me?  My French is nowhere near good enough for this one. ;o]

Cheers, and good luck.

__
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices. 
http://auctions.yahoo.com/



Re: long background tasks

2001-01-25 Thread Gerd Kortemeyer

You need $r-flush();

1) Send out header
2) Use $r-print(...) to give some "please be patient" message or something
3) End the first chunk of info with "br\n", so that the browser knows enough
about the page layout to start page output.
4) Use $r-flush();
5) Do your long task
6) Produce rest of your page

- Gerd.

Paul wrote:
 
 --- Louis-David Mitterrand [EMAIL PROTECTED] wrote:
  Hello,
 
  Were are trying to run long a task (DB import) from a HTML::Mason
  page and are trying to send an immediate response to the user while
  the task is running. Here is our pseudo-code:
 
  %init
  sub long_running_task {
# lottsa long, boring stuff
  }
  $r-puch_handlers(PerlCleanupHandler=\long_running_task($myarg));
  /%init
 
  The rest of the page sends back HTML. The problem is that it _not_
  sent back until the long_running_task function has completed.
 
  I thought that when registering a code ref in that way the sub{}
  would not be called until later during the PerlCleanupHandler phase.
 
  Am I missing something, is there a better way to do it?
 
  Thanks in advance for your insight,
 
 Since you're pushing that handler onto the cleanup phase, I'm assuming
 that you don't mean to send any more data to the client. It sounds like
 the buffer isn't getting flushed (though I can't imagine why). Maybe if
 you flush it manually? "local $|=1" or something?
 
 I've had this problem in cases where I wanted to fork a long running
 subprocess, because the child's STDIN and STDOUT are still pegged to
 the browser socket. For a child, it works pretty well to close and
 reopen the STD' filehandles to dissociate from the client after the
 fork (like running a daemon).
 
 Would that do for what you need here?
 
  --
   HIPPOLYTE: Quelques crimes toujours prcdent les grands crimes.
  Quiconque a pu franchir les bornes lgitimes
  Peut violer enfin les droits les plus sacrs ;
(Phdre, J-B Racine, acte
  4, scne 2)
 
 ...since I don't have a copy of Phaedra on my desk, would you translate
 this for me?  My French is nowhere near good enough for this one. ;o]
 
 Cheers, and good luck.
 
 __
 Do You Yahoo!?
 Yahoo! Auctions - Buy the things you want at great prices.
 http://auctions.yahoo.com/

begin:vcard 
n:Kortemeyer;Gerd
tel;fax:(517) 432-2175
tel;work:(517) 432-5468
x-mozilla-html:TRUE
url:http://www.lite.msu.edu/kortemeyer/
org:Michigan State University;LITE Lab
adr:;;123 North Kedzie Labs;East Lansing;Michigan;48824;USA
version:2.1
email;internet:[EMAIL PROTECTED]
title:Instructional Technology Specialist
x-mozilla-cpt:;3
fn:Gerd Kortemeyer
end:vcard



Re: long background tasks

2001-01-25 Thread Gerd Kortemeyer

Sorry all, this should have been $r-rflush() - too many r's ... I guess the
additional "r" was meant as a reminder that this is a low-level call, and
flushing buffers results in a performance hit, and should not be done for no
good reason.

- Gerd.

Gerd Kortemeyer wrote:
 
 You need $r-flush();
 
 1) Send out header
 2) Use $r-print(...) to give some "please be patient" message or something
 3) End the first chunk of info with "br\n", so that the browser knows enough
 about the page layout to start page output.
 4) Use $r-flush();
 5) Do your long task
 6) Produce rest of your page
 
 - Gerd.

begin:vcard 
n:Kortemeyer;Gerd
tel;fax:(517) 432-2175
tel;work:(517) 432-5468
x-mozilla-html:TRUE
url:http://www.lite.msu.edu/kortemeyer/
org:Michigan State University;LITE Lab
adr:;;123 North Kedzie Labs;East Lansing;Michigan;48824;USA
version:2.1
email;internet:[EMAIL PROTECTED]
title:Instructional Technology Specialist
x-mozilla-cpt:;3
fn:Gerd Kortemeyer
end:vcard