From: [EMAIL PROTECTED] Operating system: Linux, 2.4.19 PHP version: 4.2.3 PHP Bug Type: Sockets related Bug description: fsockopen / fread fails unless exact length is given
Hi there... I wanted to fetch a webpage's contents. I used to be able to do so by fread'ing with a huge number as length: ////////////////// $fp=fsockopen( $host, $port, $errno, $errstr, 120 ); // assumed host and port were previously defined $headers = "GET /jornalmn/index.htm HTTP/1.0\r\n" ."User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" ."Host: www.meionorte.com\r\n" ."Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\n" ."Connection: Keep-Alive\r\n" ."Cache-Control: no-cache\r\n" ."\r\n"; fwrite($fp,$headers, strlen($headers)); $fetched_content = fread($fp,1000000000); fclose($fp); //////////////// Just recently this stopped working. Actually, I would eventually fetch the page, but only after the connection timed out. After a lot of debugging I found out I'd have sucess by specifying the EXACT file size to fread. I had to adapt my scripts and tell them to either: a) Capture the "Content-length" response value sent by the server (easy way); b) Fread little by little (128 bytes a time) and use socket_get_status($fp) everytime to check for EOF condition and the number of unread bytes. -- Edit bug report at http://bugs.php.net/?id=21202&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=21202&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=21202&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=21202&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=21202&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=21202&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=21202&r=support Expected behavior: http://bugs.php.net/fix.php?id=21202&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=21202&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=21202&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=21202&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21202&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=21202&r=dst IIS Stability: http://bugs.php.net/fix.php?id=21202&r=isapi