You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Anton Permyakov <ap...@soludium.com> on 2002/10/09 11:25:18 UTC

Forking process

Hi all,

I need to start process, which would get big amount of data from another
server into my DataBase,
and while it will do it, my browser should show me progress-bar on this data
extraction.

I have mod_perl based web-server, so, i should not use fork(), as explained
in Mod_perl docs. But also i cannot invoke system(), as this proccess could
take very long time.
What i have to do?

May be best solution is using CGI-script, which allows forking without all
Apache process forking?

Thank you,

Best wishes!
----------------------------------------------------------------------------
Anton Permyakov           Web-Developer
apermyakov@soludium.com   WWW.SOLUDIUM.COM


Re: Forking process

Posted by Perrin Harkins <pe...@elem.com>.
Aaron Johnson wrote:
> So in a nutshell
> 
> - Create a temp (flag) file
> - Generate and send the HTML to the browser which includes a meta
> refresh
> - Add the temp file to their session data (or something similar)
> - Exec a process and send the temp file name to it
> - On page refresh look to see if the temp (flag) file still exists and
> if so create a new waiting page ( meta refresh ), otherwise deliver end
> results.

Randal has a description of this process -- with code -- here:
http://www.stonehenge.com/merlyn/WebTechniques/col20.html

It's for CGI, but all the principles are the same.

- Perrin


Re: Forking process

Posted by Aaron Johnson <so...@gina.net>.
On Wed, 2002-10-09 at 05:25, Anton Permyakov wrote:
> Hi all,
> 
> I need to start process, which would get big amount of data from another
> server into my DataBase,
> and while it will do it, my browser should show me progress-bar on this data
> extraction.
> 
> I have mod_perl based web-server, so, i should not use fork(), as explained
> in Mod_perl docs. But also i cannot invoke system(), as this proccess could
> take very long time.
> What i have to do?

I needed to do this recently myself.  I am using sessions (under
HTML::Embperl) so I created a temp file and added the name of the temp
file to my session data. 

I 'exec' off the external program after I have printed "waiting" page
content.  I pass the temp file name to the external script so it can
delete it when it is done running. The waiting page includes a meta
refresh, in my case the wait is dynamically determined based on the type
of action taken and the estimated time it will take to produce the
results.

The temp file is deleted once the process was done running. When the
meta refresh occurs it reloads the same page and determines if the temp
file matching the session value still existed and if so redisplays the
appropriate waiting page with a predefined wait time (30 seconds in my
case).  If the temp file is cleared I present the user with the results.

The temp file name should be from a counter file or some form of rand
seed and/or time to avoid duplicate names while processing.  Traffic
will determine how aggressive you need to be in the uniqueness of the
file name.

So in a nutshell

- Create a temp (flag) file
- Generate and send the HTML to the browser which includes a meta
refresh
- Add the temp file to their session data (or something similar)
- Exec a process and send the temp file name to it
- On page refresh look to see if the temp (flag) file still exists and
if so create a new waiting page ( meta refresh ), otherwise deliver end
results.

Aaron Johnson

> 
> May be best solution is using CGI-script, which allows forking without all
> Apache process forking?
> 
> Thank you,
> 
> Best wishes!
> ----------------------------------------------------------------------------
> Anton Permyakov           Web-Developer
> apermyakov@soludium.com   WWW.SOLUDIUM.COM
> 
> 


Re: Forking process

Posted by Rafiq Ismail <ra...@joshua.dreamthought.com>.
On Wed, 9 Oct 2002, Anton Permyakov wrote:
> Hi all,
>
> I need to start process, which would get big amount of data from another
> server into my DataBase,
> and while it will do it, my browser should show me progress-bar on this data
> extraction.

> I have mod_perl based web-server, so, i should not use fork(), as explained
> in Mod_perl docs. But also i cannot invoke system(), as this proccess could
> take very long time.
> What i have to do?

I'm not sure that I understand what you want to do, however, have you
considered:

* writing a handler which would connect to a deamon which itself could
start the secondary process.

* The script running the secondary processes could update some datastore
which you could periodically read from to show progress.

* It might also be possible to use syscalls straight from your script to
get progress on your dataextraction - depending on what and how it is
being extracted.

* Meta-refresh the page every now and then to keep updating your progress
bar.

R.

-- 
Senior Programmer
Bookings.nl
----------------------------------------------------------
Me::rafiq@dreamthought.com||www.dreamthought.com
Budget hosting on my 10Mbit/backbone::info@dreamthought.com