Hello!
I would like to start a PHP script in the background from within another PHP script. I would like to monitor all error cases properly.
Is there an easy way to see if that background script was started successfully? The background script would write its errors into an error log that I'm monitoring. But what about starting the script itself?
I'm trying to start a background script like this:
exec('nohup php sleeps.php > /tmp/tt 2>&1 &', $output, $status);
error_log('execute_shell: ' . var_export(['status' => $status, 'output' => $output], true));
exec('nohup php sleeps_nonexist.php > /tmp/tt 2>&1 &', $output, $status);
error_log('execute_shell: ' . var_export(['status' => $status, 'output' => $output], true));
error_log('execute_shell: ' . var_export(['status' => $status, 'output' => $output], true));
exec('nohup php sleeps_nonexist.php > /tmp/tt 2>&1 &', $output, $status);
error_log('execute_shell: ' . var_export(['status' => $status, 'output' => $output], true));
The first `exec` runs all right in the background (asynchronously).
The second one behaves in exactly the same way (`$status === 0`), even though file "sleeps_nonexist.php" does not exist.
Running in the command line manually, this would give status `0`:
nohup php sleeps.php > /tmp/tt 2>&1
echo $?
echo $?
This would give status `1`:
nohup php sleeps_nonexist.php > /tmp/tt 2>&1
echo $?
echo $?
Regards,
Janis