php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21202 fsockopen / fread fails unless exact length is given
Submitted: 2002-12-26 16:05 UTC Modified: 2003-01-09 19:37 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: lastritesdf at yahoo dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 4.2.3 OS: Linux, 2.4.19
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lastritesdf at yahoo dot com
New email:
PHP Version: OS:

 

 [2002-12-26 16:05 UTC] lastritesdf at yahoo dot com
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-26 16:06 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip
 [2003-01-09 19:37 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC