Re: getting one line from file
| From: | Robin Vickery | Date: | Thu, 31 Aug 2000 15:04:20 +0000 |
| Subject: | Re: getting one line from file | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14624@lists.php.net to get a copy of this message | ||
david.perry@nerosworld.com (David Perry) writes:
> Michael,
>
> > > > >> $info =
grep "676"
> > > > >> /tmp/somefile.txt;
>
> There are some minor tricks to help like
>
> $info = `cat /tmp/somefile.txt | head -9000 | grep '676';
>
> but you would really be much better off putting 10 meg into a db engine
> and index the dickens out of it. WIth only 10k records your response time
> should be way < 1 second.
It's possible that it's inconvenient to put this file into a database (perhaps
it's a logfile generated by some other application).
Apart from piping the file through 'head' you can also use the -F switch to
grep (you're searching on a simple string not a regex) to speed things up.
It might be worth caching the returned string and subsequently checking the
file's modification time to see if the grep's really necessary.
-robin
--
Robin Vickery...............................................
Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK
Email: robin@planet-three.net Phone: +44 (0)870 729 5444