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 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/
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

Reply via email to