|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-04-17 09:13 UTC] markus dot pfefferle at web dot de
[2003-04-17 09:23 UTC] markus dot pfefferle at web dot de
[2003-04-17 09:40 UTC] wez@php.net
[2003-04-23 07:15 UTC] markus dot pfefferle at web dot de
[2003-04-25 05:44 UTC] wez@php.net
[2003-04-28 08:07 UTC] wez@php.net
[2003-04-28 09:38 UTC] markus dot pfefferle at web dot de
[2003-04-28 10:33 UTC] markus dot pfefferle at web dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 09 01:00:01 2025 UTC |
This well-known fragment of code takes up about 15 seconds on my machine: <pre> $fp = fsockopen($host, $port); fputs($fp, "POST $path HTTP/1.1\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Content-length: ". strlen($data_to_send) ."\n"); fputs($fp, "Connection: close\n\n"); fputs($fp, "$data_to_send\n"); while(!feof($fp)) { $res .= fgets($fp, 128); } </pre> In order to trace the cause fot this pause, I modified whie while-loop to give me some debugging information: <pre> while(!feof($fp)) { $r = fgets($fp, 128); echo time()." : ".var_dump($r),"\n"; } </pre> Truns out this on the final 3 lines: <pre> 1050581993 : string(2) " " 1050581993 : bool(false) 1050582009 : Array </pre> The second line that returned false should already have flipped the EOF flag on the connection, but apparently it didn't. The last call that finally flips this flag however takes up 15 seconds of time and returns (odd enough) an empty array. Alrighty I think - if the false-value of the last chunk will give me a clue to break the loop, I just change my code to this: <pre> do { $r = fgets($fp, 128); echo time()." : ".var_dump($r),"\n"; } while ($r); </pre> And guess what - exactly the same 15 seconds, exactly the same output as before. The loop didn't even exit when $r was bool(false) according to var_dump(). This is what really puzzles me. I also used fread and toyed around with any possible length-parameter. It's always these 15 seconds delay at the last read that returns this odd empty array.