|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-04-12 23:46 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 11:00:01 2025 UTC |
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); } ?>