Computing.Net > Forums > Web Development > Running Scripts in Background - PHP

Running Scripts in Background - PHP

Reply to Message Icon

Original Message
Name: drsmartman
Date: November 12, 2004 at 15:13:40 Pacific
Subject: Running Scripts in Background - PHP
OS: RH Linux AS 3
CPU/Ram: p3 x4 /1GB
Comment:

hey all,

i thought i could run a script from PHP in the background
just using the & in the shell_exec function. however, the
page seems to go until the script is done executing...it
usually times out because the scripts take several minutes
to run. what am i missing?

-- start

shell_exec('./myscript.pl &');
--end


Report Offensive Message For Removal

Response Number 1
Name: SN
Date: November 12, 2004 at 19:17:47 Pacific
Subject: Running Scripts in Background - PHP
Reply: (edit)

The only documentation I could find on this feature was using the system() function, rather than the one you used. Couldn't find anything on the ampersand functionality you're referring to.

This may apply:
Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.

Also, I think the ampersand you're referring to may actually be passing the second parameter in by reference:

// this will execute process.php asynchronously; not waiting for completion before executing the next one.
$array = array('apple', 'banana', 'pear');
foreach($array as $i)
{
system("php process.php \"fruit=$i\"");
}

// this will execute process.php 3 times, waiting for the prior command to complete before starting a new one
$array = array('apple', 'banana', 'pear');
foreach($array as $i)
{
system("php process.php \"fruit=$i\"", $status);
}

http://www.php.net/manual/en/function.system.php

-SN


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Running Scripts in Background - PHP

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software