On 2008-07-28 19:56:49 -0700, "laredotornado@zipmail.com"
<laredotornado@zipmail.comsaid:
Quote:
Hi,
>
I'm using PHP 5. I have a function that takes a little while to run,
and I don't want the user to have to wait while it does. Is there a
way to run this function in the background?
>
Thanks for your help, - Dave
We had a similar problem, and our large job took so much time, we split
it up into 10 background processes which filtered URLs in a large
database -- each of the 10 processes were operating on 1/10th of the
records in the main table. So this is what we did.
Note sending output to '/dev/null' surpressed any output from the
process; results from the PHP script were written to another database
table.
The ampersand at the end & meant to run the process in the background
(as a lower priority than foreground processes.)
Of course this is an approach that can be used if you are using
colocation or a dedicated server; if you use shared hosting, your ISP
may limit the use of the PHP exec () command:
$pathToPHPbinary = '/u01/apps/php/5.1.4/bin/php';
$pathToScriptToSpawn = '/u01/apps/www/runTests/siteFilter.php';
$limit = 10;
for ($i=1; $i<=$limit; ++$i)
{
exec ("$pathToPHPbinary $pathToScriptToSpawn $i $limit >/dev/null &");
}