# feof hangs (bug #25939)

- Thread: https://externals.io/message/10109
- Original archive: https://news-web.php.net/php.internals/10109
- Started by Christian Schneider on 2004-05-27T12:38:30+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10109 — Christian Schneider — 2004-05-27T12:38:30+00:00

URL: https://externals.io/message/10109#10109

I tried to reopen bug #25939 <http://bugs.php.net/bug.php?id=25939> 
because I ran into the same problem as <topace at lightbox dot org> but 
it's not my bug report. Should I open a new bug?

I agree with the last comment that feof should not hang.

Sample script:
$fd = fsockopen('www.php.net', 80);
feof($fd);

This hangs for PHP >= 4.3.5 and PHP 5

Regards,
- Chris

---

## #10110 — Wez Furlong — 2004-05-27T13:08:31+00:00

URL: https://externals.io/message/10109#10110 · In reply to: #10109

I just fixed PHP 5, but can't see how 4.3 could hang (admittedly only looked
briefly).
I have to go out for a couple of hours; if you could track down where PHP is
blocking in the 4.3 branch, I'd very much appreciate it.

--Wez. 

> -----Original Message-----
> From: Christian Schneider [mailto:cschneid@cschneid.com] 
> Sent: 27 May 2004 13:39
> To: internals@lists.php.net
> Subject: [PHP-DEV] feof hangs (bug #25939)
> 
> I tried to reopen bug #25939 <http://bugs.php.net/bug.php?id=25939> 
> because I ran into the same problem as <topace at lightbox 
> dot org> but 
> it's not my bug report. Should I open a new bug?
> 
> I agree with the last comment that feof should not hang.
> 
> Sample script:
> $fd = fsockopen('www.php.net', 80);
> feof($fd);
> 
> This hangs for PHP >= 4.3.5 and PHP 5
> 
> Regards,
> - Chris

---

## #10111 — Christian Schneider — 2004-05-27T13:22:17+00:00

URL: https://externals.io/message/10109#10111 · In reply to: #10110

Wez Furlong wrote:
> I have to go out for a couple of hours; if you could track down where PHP is
> blocking in the 4.3 branch, I'd very much appreciate it.

It hangs in main/network.c the change introduced from 1.83.2.20 to 
1.83.2.21 in the select shown here if no data can be read (yet). This 
doesn't mean that we encountered an eof though. (Another small nitpick 
is that tv.tv_usec is not initialized if default_socket_timeout is used).

main/network.c:
@@ -1139,9 +1139,15 @@
         int alive = 1;
         int fd = sock->socket;
         fd_set rfds;
-       struct timeval tv = {0, 0};
+       struct timeval tv;
         char buf;

+       if (sock->timeout.tv_sec == -1) {
+               tv.tv_sec = FG(default_socket_timeout);
+       } else {
+               tv = sock->timeout;
+       }
+
         /* logic: if the select call indicates that there is data to
          * be read, but a read returns 0 bytes of data, then the socket
          * has been closed.
          */

         FD_ZERO(&rfds);
         FD_SET(fd, &rfds);
         if (select(fd+1, &rfds, NULL, NULL, &tv) > 0) {
