|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49706 feof() returns true before reaching end of stream
Submitted: 2009-09-29 06:20 UTC Modified: 2009-10-11 01:00 UTC
Avg. Score:4.5 ± 0.7
Reproduced:10 of 11 (90.9%)
Same Version:9 (90.0%)
Same OS:1 (10.0%)
From: alex at innovacomputing dot com Assigned:
Status: No Feedback Package: Streams related
PHP Version: 5.2.11 OS: Debian 5.0.3/amd64
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: alex at innovacomputing dot com
New email:
PHP Version: OS:


 [2009-09-29 06:20 UTC] alex at innovacomputing dot com
feof() seems to have broken on socket streams somewhere between version 5.2.9 and 5.2.11.

When running the code included in this bug report on PHP 5.2.9, it returns "bool(false)", which is the correct behavior.  However, when upgrading to PHP 5.2.11, feof() will incorrectly return "bool(true)".

Note that I've only been able to reproduce this on a 64-bit server.  PHP 5.2.11 on the 32-bit server that I've also tested with correctly returns "bool(false)".

Reproduce code:
list($a, $b) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
fwrite($a, 'Test');

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-29 07:21 UTC] tantaoui at gmail dot com
It works correctly for me in 5.2.10 but not in 5.2.11 under Windows Server 2003. it seems to be OK in 5.2.12 (snapshot)
 [2009-09-29 10:54 UTC]
Please try using this snapshot:
For Windows:

 [2009-10-03 09:59 UTC]
Please try a 5.3 snapshot as well.
 [2009-10-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-11-18 12:05 UTC] doughton at hiden dot co dot uk
Problem is manifesting itself in Mantis 1.1.0a1 with mail reporting script running on SunOS
Machine hardware:   sun4u
OS version:         5.10
Processor type:     sparc
Hardware:           SUNW,Ultra-250

 feof erroneously returns true when reading from a socket to the POP3 server ( Qpopper version 4.1b18). This results in readLine in socket.php randomly returning an empty string when called from _recvLn() in POP3.PHP , so this breaks all the functions in POP3.PHP

Commenting out feof in readLine fixes this problem:
 function readLine()
        if (!is_resource($this->fp)) {
            return $this->raiseError('not connected');

        $line = '';
        $timeout = time() + $this->timeout;
        while (/* !feof($this->fp) && */ (!$this->timeout || time() < $timeout)) {
            $line .= @fgets($this->fp, $this->lineLength);
            if (substr($line, -1) == "\n") {
                return rtrim($line, "\r\n");
        return $line;
As feof( ) seems to randomly return true I suspect a timing issue, probably depends on whether the mail server has written to the socket before feof is called - our mail server resides on another server.

Could this be related to the fix for PHP bug 49072 (feof never returns true for damaged file in zip). ?

It is fixed in the latest version ( 5.12 release candidate 2 ).
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 01:01:32 2024 UTC