Re: Re: Opening large file problem - fopen

From: Date: Tue, 16 Dec 2003 13:28:44 +0000
Subject: Re: Re: Opening large file problem - fopen
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-172801@lists.php.net to get a copy of this message
Hello, Thanks for you reply. The first approach works, I succesfully imported 1.903.541 entries into my mySQL database, phew! Problem was that as mentioned I had to "massage" the data beforehand, which with TextPad didnt take to much time but again I love my scripts to be complete and be "standalone". Back to the 2) option, I tried another approach, just to see how far the script woul accually go. There are ~2,1 million lines in the error_log so I would like to see a result for the $i in this range. But this script also chokes. $file = "error_log"; $handle = fopen ($file, "rb"); $contents = ""; do { $data = fread($handle, 8192); if (strlen($data) == 0) { break; } $contents = $data; $temp = explode("\n",$contents); $i = $i + count($temp); if($i%1000==0) // Spit out every 1000 lines count echo $i . "<br>"; } while(true); fclose ($handle); echo $count; exit; Do you have an example, or link to a site discussing the issue, of buffering the data? -- Kim Steinhaug --------------------------------------------------------------- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --------------------------------------------------------------- "Eugene Lee" <list-php-1@fsck.net> wrote in message news:20031216130100.GC1537@Dark-Age.local... > On Tue, Dec 16, 2003 at 01:30:14PM +0100, Kim Steinhaug wrote: > : > : I found out that what the script accually does is choke on "\n\n", > : empty lines. I havnt found a way to solve this with the script, > : > : What I do now is use TextPad and just replace all occurencies > : of "\n\n" with "\n-\n" or something and it works all nice. But this > : is a bad way of doing it, since the script still doesnt accually work... > > You have two options: > > 1) massage your data beforehand so that your script works properly > > 2) buffer your input lines so that you process them only after you have > read a complete "entry", since one entry may span multiple lines in your > error_log.

« previous php.general (#172801) next »