|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-11-28 15:17 UTC] nunoplopes at sapo dot pt
Description: ------------ I opened a socket using fsockopen and then I send some data using fputs. Then I try to read data either using feof of fgets. If the servers returns 2 lines and I call three times the fgets(), the script times out when it reaches the 30 seconds. If I only call fgets 2 times, everything works fine. feof also stops the script execution. So, I have no way to know if servers' response has ended or not. Reproduce code: --------------- Get the code from CVS at: http://cvs.sourceforge.net/viewcvs.py/phpdocmanager/phpcvsclass/ Or just a small example: <? if ($handle = fsockopen ("cvs.php.net", 2401, $errno, $errstr, 30)) { $text = "BEGIN AUTH REQUEST\n"; $text .= "/repository\n"; $text .= "cvsread\n"; $text .= "A\n"; $text .= "END AUTH REQUEST\n"; fputs ($handle, $text); fgets($handle); // "I LOVE YOU\n" fputs ($handle, "version\n"); echo fgets($handle); echo fgets($handle); echo fgets($handle); fclose($handle); } ?> Expected result: ---------------- M Concurrent Versions System (CVS) 1.12.2 (client/server)\n ok Actual result: -------------- timeout PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 20:00:01 2025 UTC |
I've installed the new snapshot (Nov 29, 2003 17:30 GMT). The script still times out. The example I wrote before still doesn't work, but there is other with feof that works. Really strange.... Working script: <? $fp = fsockopen ("pt.php.net", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br>\n"; } else { fputs ($fp, "GET / HTTP/1.1\r\n"); fputs ($fp, "Host: pt.php.net\r\n"); fputs ($fp, "Connection: Close\r\n\r\n"); while (!feof($fp)) { echo fgets ($fp,128); } fclose ($fp); } ?>