Starting a long running task from a web server is a reasonable, though unusual, thing to do. I did it once about 10 years ago on a Linux system.

In my CGI script (in Perl), I included something like:

# define the task my $task = <<'_EOT_'; # use ' to prevent interpolation #!perl -T # use -T to specify taint mode use strict; use warnings; # (your processing goes here) # (generate and send notification - suggest using Mail::Sendmail) __DATA__ _EOT_ # append the data $task .= join "\n", @data; # save the task open my $tf, '>', $tmpfile; print $tf $task; close $tf; # submit the task system('batch', '-M', '-f', $tmpfile); # (tell user the task has been submitted)

Note that I used an often neglected feature of Linux/Unix/POSIX - the batch command. This command is usually part of the "at" package, so if batch is not available on your Linux/Unix/POSIX computer, that's what to install.

FYI, the batch command queues the specified task when the machine is not too busy. Tasks in the queue will be run in the order they were queued.

If you can't use batch (or similar), try:

system("nohup $tmpfile &");

But using batch will reduce the risk of overloading your server.


In reply to Re: Best practice for sending results to a user via email by RonW
in thread Best practice for sending results to a user via email by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.