RE: [PHP] getting one line from file

From: Date: Thu, 31 Aug 2000 13:31:23 +0000
Subject: RE: [PHP] getting one line from file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14594@lists.php.net to get a copy of this message
Well a 9 meg text file is a bit large. Well grep is very fast to find the line you need, but calling it from php can be a bit slow on big files. If i were you i would try reading the file, and compare that to the time it took to do the grep. open the file, read line by line and check to see if the line conatins that number, makre sure you dont use eregi for this, as it's slower, use preg or ereg. see if thats faster, it may be, since you not forking a sepreate process, it may be faster. Chris On Thu, 31 Aug 2000, Michael Packer wrote: > > The text file i'm search is 9,859,103 bytes (today, it will be a bit larger > tomorrow) > (30,072 lines) > > generally the line i'll be looking for is in the first 9,000 or so lines... > the web server that i'm doing this on is dual p3 500 with 512mb > > i'm only looking for the one line that contains a specific number (and i > know for a > fact that the number will not (ever) be duplicated in another line. > > pac > > > > > > how big is the file your reading? > > > > How beefy is your webserver? > > > > Is this file one line? if so why grep? thats overhead you dont need? > > just open the file, and put the whole thing into any array, then access > > what you need. It will probally be quicker then doing a system call, and > > using grep tooo, , all that causes overhead. on the other hand if this > > file is a big one, that will wlos you down to. > > > > On Thu, 31 Aug 2000, Michael Packer wrote: > > > > > > > > > pac@stingrayboats.com ("Michael Packer") writes: > > > > > > > >> I'm just learning PHP and have a question....in perl I used > > to do this: > > > >> > > > >> $info = grep "676" > > > >> /tmp/somefile.txt; > > > >> (i know there was only one line in the file with that number, > > > >>thats why it's not @info) > > > >> > > > >> i need to only get one line out of this file that is very large > > > >>(which is why i don't want to open it read through the file > > until i find > > > >>the correct line)... > > > > > > > > try this: :-) > > > > > > > > $info = grep "676" /tmp/somefile.txt; > > > > > > > > > well i tried this..it works, but damn it take a performance > > hit...do system > > > calls rereally effect PHP that much? > > > > > > instead of instantly loading, it now takes about 2-3 seconds > > > > > > any other ideas? > > > > > > thanks! > > > pac > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#14594) next »