php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72256 echo statement on invalid fd cause php to abort
Submitted: 2016-05-23 07:32 UTC Modified: 2024-07-14 09:47 UTC
Votes:3
Avg. Score:2.3 ± 0.9
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: prinbra at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: prinbra at gmail dot com
New email:
PHP Version: OS:

 

 [2016-05-23 07:32 UTC] prinbra at gmail dot com
Description:
------------
on cli environment, when the stdout of php becomes unavailable, eg: user run php in background and logged out of their ssh connection.
a echo statement will cause php process to exit immediately!

strace output:

14937 12:22:18.958295 write(1, "running\n", 8) = -1 EIO (Input/output error)

then php just silently quit!


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-25 20:46 UTC] ab@php.net
Thanks for the report. When user is logged out, the whole session becomes invalid. This should be solvable by using nohup or running PHP in screen/tmux.

Thanks.
 [2016-05-27 05:13 UTC] prinbra at gmail dot com
er, my point is: may be the php process shouldn't quit if echo failed.

the fail of fprintf  does not cause php to quit? why echo is so special and so fragile?

example:
fprintf.php
<?php
fprintf(STDOUT, "hello, world\n");
fclose(STDOUT);
fprintf(STDOUT, "hello, world2\n");
fprintf(STDERR, "hello, world2 in stderr\n");

output:
hello, world
PHP Warning:  fprintf(): 2 is not a valid stream resource in /tmp/t.php on line 4
hello, world2 in stder


however, if change fprintf to echo, php will quit early.
 [2021-12-15 14:01 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-12-15 14:01 UTC] cmb@php.net
Behavior confirmed: <https://3v4l.org/sJeMB>.

Interestingly, running the script on a debug version of PHP,
won't exhibit this behavior.  Instead, I get:

    hello, world
    bool(true)
    hello, world2
    hello, world2 in stderr

> the fail of fprintf  does not cause php to quit? why echo is so
> special and so fragile?

To begin with, fprintf() explicitly requests the resource, and
notices that it has been closed, so it doesn't actually try to
write anything to stdout (the warning goes to stderr by default).
 [2024-07-14 09:47 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 13:01:27 2024 UTC