ID:               32688
 User updated by:  rene dot vogt at cnlab dot ch
 Reported By:      rene dot vogt at cnlab dot ch
-Status:           Feedback
+Status:           Open
 Bug Type:         Sockets related
 Operating System: Windows 2003 Server
 PHP Version:      5.0.4
 New Comment:

I found the solution, sorry this is NO php bug. 
I have to check how many bytes I get by the fread function. If this
returns 0 bytes a timeout has occurd. I though I would get an eof but
this is not the case. 
You can close this ticket.

The correct code should look like this:
<?php
 $fp = fsockopen("verkehr.cnlab.ch", 80, $errno, $errstr, 3);
 if (!$fp) {
   return "Error connecting";
 } else {
   stream_set_timeout($fp, 3);
   fwrite($fp,"GET /test2.php HTTP/1.0\r\nHost:
verkehr.cnlab.ch:80\r\nConnection: Close\r\n\r\n");
   $bufferlen=-1;
   while (!feof($fp) && $bufferlen!=0) {
     $buffer = fread($fp, 512);
     $bufferlen=strlen($buffer);
     echo $buffer; flush(); ob_flush();
   }
   fclose($fp);
}
?>


Previous Comments:
------------------------------------------------------------------------

[2005-04-13 17:21:54] [EMAIL PROTECTED]

With what version it worked before?
I doubt it could work at all in the way you describe, because in this
situation there is _no timeout_, it's quite expected situation: you
open a stream and read the data from it, so why should it timeout? 

------------------------------------------------------------------------

[2005-04-12 23:46:03] rene dot vogt at cnlab dot ch

Description:
------------
The function stream_set_timeout seems not to work on php 5.0.4 (win32).
It worked with earlier php versions.
The sample code connects to a page on a server which prints out a dot
every second. After 3 seconds the script should terminate.

http://verkehr.cnlab.ch/test1.php (sample code) 
http://verkehr.cnlab.ch/test2.php (produces dots)

Reproduce code:
---------------
<?php
 $fp = fsockopen("verkehr.cnlab.ch", 80, $errno, $errstr, 3);
 if (!$fp) {
   return "Error connecting";
 } else {
   stream_set_timeout($fp, 3);
   fwrite($fp,"GET /test2.php HTTP/1.0\r\nHost:
verkehr.cnlab.ch:80\r\nConnection: Close\r\n\r\n");
   while (!feof($fp)) {
     echo fread($fp, 512);flush(); ob_flush();
   }
   fclose($fp);
}
?>

Expected result:
----------------
Prints out 3 dots and abort


Actual result:
--------------
Print out dots until page timeout


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32688&edit=1

Reply via email to