note 35527 rejected from function.fread by didou

From: Date: Wed, 15 Oct 2003 11:58:51 +0000
Subject: note 35527 rejected from function.fread by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58627@lists.php.net to get a copy of this message
Note Submitter: yaroukh@email.cz ---- Is the FRead() function usable only with binary files? I open a socket, send http-request, then read the reply and save its data part. With binary files (images) this works fine - it's fast and the data are 100% correct. But each text file takes >15sec to read, it contains hexa-numbers representing lengths of each transferred data-block, but yet the copied file is smaller than the original one; I supposed this could be caused by the different EOL - I mean the "\n" vs "\r\n", but the difference is way bigger than the number of lines in the file. What am I doing wrong PLZ? I've noticed that with text files Apache doesn't send Content-Length and ETag information; could this be the catch? tested on localhost which is PHP 4.3.2 + Win2k + Apache 2.0.46 this is how I read the http-response: <? function getUrl($url, $httpReferrer = "", $username = "", $password = "") { // build the request { $urlParts = parseUrl($url, false); // split an URL into protocol, username, password, hostname, port, path, filename, query if($httpReferrer == "") $httpReferrer = $urlParts[protocol].$urlParts[host].$urlParts[path]; $request = "GET ".$urlParts[path]." HTTP/1.1\r\n". "Accept: */*\r\n". "Accept-Language: en-us\r\n". "Connection: Close\r\n". "Host: ".$urlParts[host]."\r\n". "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n". (($username and $password) ? "Authorization: Basic ".Base64_Encode($username.":".$password)."\r\n" : ""). "Referer: ".$httpReferrer."\r\n". # "Accept-Encoding: gzip, deflate\r\n". "\r\n"; // } $port = ($urlParts[port]) ? ($urlParts[port]) : 80; if($fp = FSockOpen($urlParts[host], $port, $errorNumber, $errorMessage, 15)) { FWrite($fp, $request); $headers = Array(); // read the headers { while(!FEOF($fp)) { $header = Trim(FGetS($fp, 128)); if($header == "") break; $headers[] = $header; } // } // read the data { while(!FEOF($fp)) $data .= FRead($fp, 4096); // } FClose($fp); return $data; } else { print $errorMessage; Die("connection failed"); } } ?>

« previous php.notes (#58627) next »