|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47893 CLI script with non-blocking STDIN terminates randomly
Submitted: 2009-04-03 23:17 UTC Modified: 2009-04-07 16:12 UTC
From: jon at thesquareplanet dot com Assigned:
Status: Closed Package: CGI/CLI related
PHP Version: 5.2CVS-2009-04-03 (snap) OS: Debian Lenny
Private report: No CVE-ID: None
 [2009-04-03 23:17 UTC] jon at thesquareplanet dot com
When setting STDIN to be non-blocking, and then running fread() on it, the cli script suddenly terminates at a seemingly random point during the reading. No error message is given.

Seemingly related bugs: <-- This is the same bug, but has erroneously been labeled as a dupe of the one below <-- This bug describes a somewhat similar, though not nearly identical, problem

These bugs are both set as last modified in 2003/2004, but the issue remains unfixed.

Reproduce code:
stream_set_blocking(STDIN, FALSE);
while (1) {
echo "\n";;

Expected result:
A never-ending sequence of var_dumps of either an empty string or a typed character

Actual result:
The expected output, but only for a short while, and then the script terminates


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-03 23:18 UTC] jon at thesquareplanet dot com
A discussion of this bug can also be found at:
 [2009-04-04 15:48 UTC]
This is reproducible with this script too:

stream_set_blocking(STDIN, 0);
$str = str_repeat("a", 65535);

This is caused by STDOUT being non-blocking if your shell passes the same descriptor for STDOUT and STDIN (the write fails with EAGAIN and PHP aborts).

Running the same script with different STDIN/STDOUT does not reproduce the problem, e.g.
php test.php >/dev/null
php test.php </dev/null
 [2009-04-07 16:12 UTC]
This bug has been fixed in CVS.

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 May 23 18:01:35 2024 UTC