Re: Return a 200 0K status and send the content of the request later
Vincent Veyron <[email protected]> Wed, 14 May 2025 02:23:35 +0200
| Newsgroups | gmane.comp.apache.mod-perl |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 13 May 2025 14:57:15 -0500 Mithun Bhattacharya <[email protected]> wrote: Hi Mithun, > Hence if you are writing a mod_perl handler for such an endpoint you retu= rn > success immediately and then start processing the request. In most cases > this is simply a matter of doing $r->print on the headers followed by pri= nt > of two new lines. >=20 Nice! Your comment made me revisit mod_perl's documentation, and I found this : https://perl.apache.org/docs/2.0/user/coding/coding.html#Forcing_HTTP_Respo= nse_Headers_Out The following works, where exportation($r) is the long running sub that bui= lds a tar file and returns a page with a link to the file, for the user to = click. '<h3>Building tar file</h3>' does get sent first, then the rest of t= he response after completion of the sub. $r->content_type('text/html; charset=3Dutf-8') ; $r->print('<h3>Building tar file</h3>') ; $r->rflush; # send the headers out $r->print( exportation($r) ) ; return Apache2::Const::OK ; This is great, I can thus send a message to the user, maybe with an estimat= ed time of arrival. Thanks for the help. I have an another question, if I may. Is there a way I could do : $r->print('<h3>Building tar file</h3>') ; every second or other until the tar file is built? I can't seem to think of= one. My handler calls an sql script that dumps the database with system() : @args =3D ('psql', '-f', '/path/to/script/to/export_raw_data.sql', '-v'= , 'id_client=3D' . $r->pnotes('session')->{id_client}, '-v', 'database=3D'= . $database, 'postgres') ; system(@args) =3D=3D 0 or warn "system @args failed: $!" ; then waits for the resulting file before proceeding to compress and tar it,= also with a system() call.=20 How can I wrap this in a loop that re-sends the 'Building tar file' message= until the file exists? --=20 Bien =E0 vous, Vincent Veyron=20 https://marica.fr/=20 Logiciel de suivi des contentieux juridiques, des sinistres d'assurance et = des contrats