Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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).


In reply to Re: Using parent and child processes in perl by sundialsvc4
in thread Using parent and child processes in perl by perl-nun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found