#23258 [NEW]: fgets() hangs 15 seconds on EOF of a socket

From: Date: Thu, 17 Apr 2003 12:35:52 +0000
Subject: #23258 [NEW]: fgets() hangs 15 seconds on EOF of a socket
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-37807@lists.php.net to get a copy of this message
From: markus dot pfefferle at web dot de Operating system: Windows 2000 PHP version: 4.3.1 PHP Bug Type: Sockets related Bug description: fgets() hangs 15 seconds on EOF of a socket 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. -- Edit bug report at http://bugs.php.net/?id=23258&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=23258&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=23258&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=23258&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=23258&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=23258&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=23258&r=support Expected behavior: http://bugs.php.net/fix.php?id=23258&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=23258&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=23258&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=23258&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23258&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=23258&r=dst IIS Stability: http://bugs.php.net/fix.php?id=23258&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=23258&r=gnused

« previous php.bugs (#37807) next »