|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49819 STDOUT losing data with posix_isatty()
Submitted: 2009-10-09 12:50 UTC Modified: 2010-05-18 09:25 UTC
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: cschneid at cschneid dot com Assigned: mike (profile)
Status: Closed Package: Streams related
PHP Version: 5.2, 5.3, 6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: cschneid at cschneid dot com
New email:
PHP Version: OS:


 [2009-10-09 12:50 UTC] cschneid at cschneid dot com
The PHP streams for stdin, stdout and stderr are seekable which results in php_stream_flush() and seek being called on it.

For some reason php_stream_flush() fails to actually write the data while still calling seek and resetting the stream position.

Suggested solution:
- Find out why php_stream_flush() fails and fix it (I don't know enough about it)
- Mark (some? all?) stdio streams as PHP_STREAM_FLAG_NO_SEEK in sapi/cli/php_cli.c (see patch)
- Mark stdio streams as PHP_STREAM_FLAG_NO_SEEK in ext/standard/php_fopen_wrapper.c

Reproduce code:
php -r 'echo "hello1\n"; posix_isatty(STDOUT); echo "hello2\n";' >out; cat out

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-09 12:54 UTC] cschneid at cschneid dot com
--- sapi/cli/php_cli.c  (revision 289412)
+++ sapi/cli/php_cli.c  (working copy)
@@ -565,6 +565,10 @@
        s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;

+       s_in->flags  |= PHP_STREAM_FLAG_NO_SEEK;
+       s_out->flags |= PHP_STREAM_FLAG_NO_SEEK;
+       s_err->flags |= PHP_STREAM_FLAG_NO_SEEK;
        s_in_process = s_in;

        php_stream_to_zval(s_in,  zin);
 [2009-10-11 09:41 UTC]
Could reproduce with PHP 5.3-HEAD.
 [2010-03-09 01:22 UTC]
-PHP Version: 6SVN-2009-10-09 (SVN) +PHP Version: 5.2, 5.3, 6
 [2010-05-18 09:25 UTC]
Automatic comment from SVN on behalf of mike
Log: * fixed bug #49819: STDOUT losing data with posix_isatty()
 [2010-05-18 09:25 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: mike
 [2010-05-18 09:25 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 10:01:29 2024 UTC