News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Paul Gregg's Blog:
"tail -# file" in PHP
April 24, 2009 @ 12:02:42

Paul Gregg has written up an example of what he calls "tail -# file for PHP" (starting from the end of file and moving backwards a given number of lines).

Here I will demonstrate a fairly tuned method of seeking to the end of the file and stepping back to read sufficient lines to the end of the file. If insufficient lines are returned, it incrementally looks back further in the file until it either can look no further, or sufficient lines are returned.

His script meets two goals - reading enough lines in for the request and keeping those lines to a minimum. His code grabs the size of the file and opens the file as a resource to fseek to a certain point and read in the lines from the defined start to finish and push them into an array. You can see the source here and a sample execution here.

0 comments voice your opinion now!
tail log file fseek example read


blog comments powered by Disqus

Similar Posts

Matthew Weier O'Phinney's Blog: ZF+Dojo Webinar

Zend Developer Zone: Two Security Tips - Naming Scheme & Input Filtering

Thomas Larsson\'s Blog: Asynchronous file upload with AJAX progress bar in PHP

JellyandCustard.com: Using DirectoryIterator to List Files in PHP

Mike Potter\'s Blog: PHP Gallery Integration with Flex - With Source Code


Community Events





Don't see your event here?
Let us know!


language interview tool artisanfiles symfony release series opinion security introduction podcast framework composer conference version library list voicesoftheelephpant community laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework