Question on Using fgets for Network I/O while Limiting Amount of Data Retrieved

From: Date: Mon, 01 Apr 2002 20:11:54 +0000
Subject: Question on Using fgets for Network I/O while Limiting Amount of Data Retrieved
Groups: php.general 
Request: Send a blank email to php-general+get-91015@lists.php.net to get a copy of this message
Hi, I'm trying to limit the amount of content retrieved with fgets when pulling data from a url. I'm generating page extracts and only need the first 2K to 4K. What I'm finding is that when I limit fgets, I get NOTHING but run within a while loop, I get the whole string. What works: //retrieve the page from the Internet $file = @fopen ("$url", "r"); // bcg need to add error handling so if website is offline, page is still logged and retrieved later if (!$file) { //log error //need to write logging code } else { //load the file into a string var while (!feof ($file)) { $string = $string . fgets($file, 4096); } } What fails: //retrieve the page from the Internet $file = @fopen ("$url", "r"); // bcg need to add error handling so if website is offline, page is still logged and retrieved later if (!$file) { //log error //need to write logging code } else { //load the file into a string var while (!feof ($file)) { $string = $string . fgets($file, 4096); break; } } I've done it with and without the while loop, tried if tests and such. Its strange. Thanks in advance J. Scott Johnson Physical * * * * * * * * * * * * * * * * * * * * * * * * * * 80 Spring Road Nahant, MA 01908 Phone: * * * * * * * * * * * * * * * * * * * * * * * * * * 781 592 0262 - home 617 970 4719 - cell Virtual: * * * * * * * * * * * * * * * * * * * * * * * * * * sjohnson@fuzzygroup.com http://www.fuzzygroup.com/ Yahoo IM: fuzzygroup

« previous php.general (#91015) next »