NYCPHP Meetup

[nycphp-talk] Reading just a couple lines of a file?

Ben Sgro ben at projectskyline.com
Wed Mar 26 11:39:11 EDT 2008


Hello,

Performance: Yeah, you don't have to hold the entire file in memory. Use 
fopen/fread and iterate through
with a buffer size.

- Ben
leam wrote:
> Is there a performance benefit and way to read just the first few lines
> of a 5k-10k file? I'm dealing with 20-300 files at a time. 
>
> Pseudo code would look something like this:
>
> DirectoryIterator  (Thank you PHP CookBook!)
> 	for each file:
> 	open file to read
> 	match $title to stuff between title HTML tags
> 	put $title into an array based on catagory
> 	put filename into an array (index matches the $title array)
> 	close file
>
> Go through the $title arrays in Catagory sequence
> 	Echo $Catagory
> 	sort $title array alphabetically
> 	echo "a href filename" $title "/a"
>
> Leam
>
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
>   



More information about the talk mailing list