php.net |  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
Votes:1
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
 [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.

example:

$s = fsockopen("localhost",25);
socket_set_timeout($s,0,100000);

$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
fputs($s,"NOOP\r\n");
$rply = fgets($s,129); # times out; data is available
fputs($s,"QUIT\r\n");
$rply = fgets($s,129); # times out; data is available
fclose($s);

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) {
                php_sockread_internal(sock);
        }
***************
*** 619,624 ****
--- 620,627 ----
        }

        SEARCHCR();
+
+         sock->timeout_event = 0;

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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


 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Apr 02 23:01:23 2020 UTC