Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Using parent and child processes in perl

by sundialsvc4 (Abbot)
on Jul 14, 2013 at 20:47 UTC ( #1044237=note: print w/replies, xml ) Need Help??

in reply to Using parent and child processes in perl

Another “big picture” consideration is ... what do you do if the user impatiently mashes Reload?   If you are not careful, very soon you have a bunch of forked-processes all getting in one another’s way.

One simple-but-effective way to deal with this sort of thing is to define a database table as a work-to-do queue.   Your web-page simply adds a request record to this table, then provides the user with a way to monitor until (the database entry now says that) the work has been completed.

How does the work get completed?   How about a simple cron task that goes off once-a-minute?   The process that is fired works like this:

  1. Check for the presence of a lockfile.   If one exists, exit.   (You’re a duplicate.)
  2. Create a lockfile.   (There are CPAN modules for this ...)
  3. Query the database for work to do.   If no (more) entries exist, remove the lockfile and exit.   Otherwise, select an entry, mark it “in progress,” do it, and then mark it “done.”
  4. goto 3

You can get fancier than this, of course, but the bottom line is that there are entirely separate processes, periodically fired or always-running, which do the work, while the web-page monitors it (and provides the means to return results to the user).

  • Comment on Re: Using parent and child processes in perl

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1044237]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-11-21 20:09 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (310 votes). Check out past polls.