I\'m calling this in my php script:
exec(\"gutschein.php >/dev/null 2>&1 &\");
Calling the script (generates a pdf and s
Try system and/or passthru. I've had issues with exec before because it halts trying to fill the return array with data until the process has finished.
These will both echo raw output so even if they work you may need to handle that with a discarded output buffer.
Please see my experience at HERE. The way I try and works for me -
php -q /path/to/my/test/script/cli_test.php argument1 < /dev/null &
In PHP, it is like
exec('php -q /path/to/my/test/script/cli_test.php argument1 < /dev/null &')
You can use screen: screen -d -m /usr/bin/php gutschein.php
Here is screen's manual if you need more info on options.
/**
* @author Micheal Mouner
* @param String $commandJob
* @return Integer $pid
*/
public function PsExec($commandJob)
{
$command = $commandJob . ' > /dev/null 2>&1 & echo $!';
exec($command, $op);
$pid = (int) $op[0];
if ($pid != "")
return $pid;
return false;
}
This worked for me .. check it
also, return processId of the background process
Can you try one of the following 2 commands to run background jobs from PHP:
$out = shell_exec('nohup /usr/bin/php /path/to/gutschein.php >/dev/null 2>&1 &');
OR
$pid = pclose(popen('/usr/bin/php gutschein.php', 'r'));
It will execute the command in background and returns you the PID, which you can check using condition $pid > 0
to ensure it has worked.
All output must be redirected, else the script will hang as long as gutschein.php executes. Try
exec('/usr/bin/php gutschein.php &> /dev/null &');