|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10001 Socket reading functions always timeout
Submitted: 2001-03-26 13:35 UTC Modified: 2002-03-18 15:18 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: chris at greatbridge dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.4pl1 OS: Linux RedHat 7.0 Kernel 2.2.17-8
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: chris at greatbridge dot com
New email:
PHP Version: OS:


 [2001-03-26 13:35 UTC] chris at greatbridge dot com
While performing read functions on a socket, fread,fgets,fgetss, with the timeout value set on the socket If a timeout occurs all subsequent calls timeout immediately.


$s = fsockopen("localhost",25);

$rply = fgets($s,129); # "220 server.domain SMTP server xyz v1.0"
fputs($s,"HELO my.domain\r\n");
$rply = fgets($s,129); # "250 Welcom my.domain"
$rply = fgets($s,129); # no data so it times out
$rply = fgets($s,129); # times out; data is available
$rply = fgets($s,129); # times out; data is available

Removing the fgets that doesn't get any data will cause the program to run as expected. Also, moving the fgets to any line will cause all lines below it to timeout even when there is data.

I tracked the the problem down in ext/standard/fclose.c to being while loops that use the sock->timeout_event variable as a condition without first reseting the variable to an appropiate value. Below is a context diff that fixes the problem.

*** /usr/local/src/php-4.0.4pl1/ext/standard/fsock.c.old        Mon Mar 26 13:07:40 2001
--- /usr/local/src/php-4.0.4pl1/ext/standard/fsock.c    Mon Mar 26 13:12:03 2001
*** 559,564 ****
--- 559,565 ----

  static void php_sockread_total(php_sockbuf *sock, size_t maxread)
+         sock->timeout_event = 0;
        while(!sock->eof && TOREAD(sock) < maxread && !sock->timeout_event) {
*** 619,624 ****
--- 620,627 ----

+         sock->timeout_event = 0;

        if(!p) {
                if(sock->is_blocked) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-18 15:18 UTC]
This bug has been fixed in CVS.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jul 07 01:04:05 2022 UTC