in reply to Best practice for sending results to a user via email
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best practice for sending results to a user via email
by choroba (Cardinal) on Apr 23, 2015 at 09:36 UTC | |
|
Re^2: Best practice for sending results to a user via email
by afoken (Chancellor) on Apr 23, 2015 at 12:21 UTC | |
|
Re^2: Best practice for sending results to a user via email
by Anonymous Monk on Apr 22, 2015 at 22:45 UTC |