|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60505 When a script exits due to write/flush failure, php cli still returns 0
Submitted: 2011-12-12 23:11 UTC Modified: -
From: Chris_Horneck at symantec dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 5.3.8 OS: Platform agnostic
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
49 - 12 = ?
Subscribe to this entry?

 [2011-12-12 23:11 UTC] Chris_Horneck at symantec dot com
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:

        $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;
                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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2024-01-23 09:20 UTC] ameliabr dot nnr at gmail dot com
The post is very useful. Thank you for this useful information. (|(
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 02:01:27 2024 UTC