arunvelusamy has asked for the wisdom of the Perl Monks concerning the following question:

Working on a CGI::Application based web application. I have a download button which on clicked, will do db fetch (based on few conditions etc...) and provide a csv file for download. The problem is, database is very big in size and takes a long time. User is unable to perform any task till this process ends.

My question is, is it possible to make a seperate process for db fetch and creation of csv file; in the mean time, the user should be able to do normal navigations between pages. plz help.

Thanks Monks,
ArunVelusamy.

Replies are listed 'Best First'.
Re: Forking of in web application
by ides (Deacon) on Aug 27, 2007 at 13:58 UTC

    You should use the IPC::Run module to fork off a process in the background that creates the file and then either have the user check back on another page to see when it is done... or better yet use some nifty Ajax to poll your app to see when it is done and provide a download link.

    Frank Wiles <frank@revsys.com>
    www.revsys.com

Re: Forking of in web application
by moritz (Cardinal) on Aug 27, 2007 at 13:57 UTC
    The Problem is that you have to tell the user when the generation of the output file is finished.

    And since you can't do a server side push reliably, you should circumvent the problem on the client side by opening another window/tab or tell the user to do so manually.

Re: Forking of in web application
by perrin (Chancellor) on Aug 27, 2007 at 15:48 UTC
Re: Forking of in web application
by TOD (Friar) on Aug 27, 2007 at 13:43 UTC
    forking in the situation you describe looks like an overhead to me. what if you optimize the structure of your database? are all columns in question indexed? must the contents your cgi-script delivers be taken from this database, or might a plain file solution be more performant?
    --------------------------------
    masses are the opiate for religion.
      Hi Tod,

      The application is a large one and the db fetch i have mentioned, uses few conditions and joining of three tables. So the db process takes some time. We have a optimized indexing on place.

      So we are tring to do something to fork this process. Will modules like "Parallel::ForkManager" help me?

      Thanks.

Re: Forking of in web application
by beryan (Scribe) on Aug 27, 2007 at 21:07 UTC
    Not possible to caching any results?