Getting script exit status code in php

In any case, to get the exit status code for php script in the background via exec ($ cmd, $ output, $ exitCode)?

For instance:

exec('PHP .php &', $output, $exitCode); 

If the trailing '&' does not turn on, then $ exitCode works as expected, always 0.

+4
source share
2 answers

For anyone who ended up here, my solution was to make a php script that takes a script as an argument. The new script is called into the background and appropriately processes exit statuses.

For instance:

 $cmd = 'php asynchronous_script.php -p 1'; exec("PHP _executor.php -c'$cmd' &"); 

The second script looks something like

 $opts = getOpt('c:'); $cmd = rtrim($opts['c'], '&'); $exitCode = 0; $output = ''; exec($cmd, $output, $exitCode); if ($exitCode > 0) { ... } 
+4
source

I found what is probably quite equivalent to the Pradeep solution. Someone posted this on the feature documentation page. http://www.php.net/manual/en/function.exec.php#101506

+5
source

Source: https://habr.com/ru/post/1333815/


All Articles