Running job in the background from Perl WITHOUT waiting for return <h3>The Disclaimer</h3> <p>First of all, I know this question (or close variations) have been asked a thousand times. I really spent a few hours looking in the obvious and the not-so-obvious places, but there may be something small I'm missing.</p> <h3>The Context</h3> <p>Let me define the problem more clearly: I'm writing a newsletter app in which I want the actual sending process to be async. As in, user clicks "send", request returns immediately and then they can check the progress in a specific page (via AJAX, for example). It's written in your traditional LAMP stack.</p> <p>In the particular host I'm using, PHP's exec() and system() are disabled for security reasons, but Perl's system functions (exec, system and backticks) aren't. So my <del>workaround</del> solution was to create a "trigger" script in Perl that calls the actual sender via the PHP CLI, and redirects to the progress page.</p> <h3>Where I'm Stuck</h3> <p>The very line the calls the sender is, as of now:</p> <pre><code>system("php -q sender.php &amp;"); </code></pre> <p>Problem being, it's not returning immediately, but waiting for the script to finish. I want it to run in the background and have the system call itself return right away. I also tried running a similar script in my Linux terminal, and in fact the prompt doesn't show until after the script has finished, even though my test output doesn't run, indicating it's really running in the background.</p> <h3>What I already tried</h3> <ul> <li>Perl's exec() function - same result of system().</li> <li>Changing the command to: "php -q sender.php | at now"), hoping that the "at" daemon would return and that the PHP process itself wouldn't be attached to Perl.</li> <li>Executing the command 'indirectly': "/bin/sh -c 'php -q sender.php &amp;'" - still waits until sender.php is finished sending.</li> <li>fork()'ing the process and executing the system call in the child (hopefully detached process) - same result as above</li> </ul> <h3>My test environment</h3> <p>Just to be sure that I'm not missing anything obvious, I created a sleeper.php script which just sleeps five seconds before exiting. And a test.cgi script that is like this, verbatim:</p> <pre><code>#!/usr/local/bin/perl system("php sleeper.php &amp;"); print "Content-type: text/html\n\ndone"; </code></pre> <h3>What should I try now?</h3>