'PHP exec run in background still waits for command in for loop
I've got a PHP for
loop that runs 3 times and executes a command. The command it executes has a sleep(3)
in there, but despite using nohup
and attempting to run in background, my for
loop is waiting 3 seconds on each iteration of my loop.
Why isn't my code executing this in it's own process and moving to the next to free up another loop?
<?php
class ScheduleRunTask extends AppShell {
/**
* Get command to run
*/
protected function getCommand() {
return 'cd ' . APP . " && Console/cake queue_manager process";
}
/**
* Main execute task
*/
public function execute() {
$maxWorkers = 3;
for ($workers = 0; $workers < $maxWorkers; $workers++) {
$this->out('running...');
$cmd = $this->getCommand();
exec('nohup ' . $cmd . ' >> /dev/null 2>&1 & echo $!', $pid);
$this->out($pid);
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|