From: Operating system: Platform agnostic PHP version: 5.3.8 Package: *General Issues Bug Type: Bug Bug description:When a script exits due to write/flush failure, php cli still returns 0
Description: ------------ Here is the scenario that causes the issue: In php.ini, ignore_user_abort=0 Have a PHP script that writes to standard out using 'echo'. The php script is launched by a shell script that redirects standard out to a file. If the partition/disk that receives the standard out file fills up while the script is running, eventually the 'echo' will cause the script to bail out because PHP was unable to write to the output stream due to the disk being full. However, the php process will exit with error code 0 even though the script never completed. The root cause is in main.c php_execute_script. If an error occurs and zend_execute_scripts returns via longjmp, both retval and EG(exit_status) will still both be 0. This makes it difficult to ascertain whether or not your script ran successfully. The obvious fix seems to be to add a zend_catch block that would set retval and EG(exit_status) to FAILURE, but I am unsure if that would have any unwanted impact. This fix doesn't make the situation any easier to debug, but it at least allows php to exit with a proper error code. Test script: --------------- <?php $logfile = $argv[1]; function doLog($msg) { global $logfile; $datestr = date("Y-M-d H:i:s T",time()); $msg="[".$datestr."]". $msg . "\n"; file_put_contents($logfile, $msg, FILE_APPEND); } doLog("Starting test"); $i = 0; while(true) { echo "Echoing a string to standard out!!!\n"; if((++$i % 10) == 0) { doLog("Completed $i iterations"); } } doLog("Script exited normally"); return 0; ?> Expected result: ---------------- Expect the script to either run to completion or that PHP would exit with an error Actual result: -------------- In the case of the above script, the script bails out without running to completion, but an error code of 0 is returned to the parent process. -- Edit bug report at https://bugs.php.net/bug.php?id=60505&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60505&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60505&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60505&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60505&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60505&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60505&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60505&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60505&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60505&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60505&r=support Expected behavior: https://bugs.php.net/fix.php?id=60505&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60505&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60505&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60505&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60505&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60505&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60505&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60505&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60505&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60505&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60505&r=mysqlcfg