On Tue, 13 May 2025 14:57:15 -0500
Mithun Bhattacharya <mit...@gmail.com> wrote:

Hi Mithun,

> Hence if you are writing a mod_perl handler for such an endpoint you return
> 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 print
> of two new lines.
> 

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_Response_Headers_Out

The following works, where exportation($r) is the long running sub that builds 
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 the response 
after completion of the sub.


        $r->content_type('text/html; charset=utf-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 estimated 
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 = ('psql', '-f', '/path/to/script/to/export_raw_data.sql', '-v', 
'id_client=' . $r->pnotes('session')->{id_client}, '-v',  'database=' . 
$database, 'postgres') ;

    system(@args) == 0 or warn "system @args failed: $!" ;

then waits for the resulting file before proceeding to compress and tar it, 
also with a system() call. 

How can I wrap this in a loop that re-sends the 'Building tar file' message 
until the file exists?



-- 
                                        Bien à vous, Vincent Veyron 

https://marica.fr/ 
Logiciel de suivi des contentieux juridiques, des sinistres d'assurance et des 
contrats

Reply via email to