News Feed
Jobs Feed
Sections




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

Sameer Borate's Blog:
Tail functionality in PHP
July 19, 2011 @ 10:16:41

Sameer Borate has posted an alternative to "tail" that you can use to find the last X number of lines in a log file you'd like to follow without having the overhead of parsing the entire file.

Frequently one needs to get the last few lines of some log files, whether php error logs or Apache logs. Most of these file sizes run into megabytes, which makes it difficult and time consuming to remotely open them using ftp. [...] The [example] is a simple but useful 'tail' implementation in PHP. I've encapsulated the tail function in a 'LogRead' class, which can be further enlarged by adding other useful log functions.

His code opens a file pointer to the requested log, grabs the file size and uses the fseek function to move the pointer to the line/location you've requested. Obviously, if the requested lines of data is large, it will still have some overhead, but this is a much better way for keeping track of the latest additions to a log. You can then use the "tail" method on the "LogRead" class to grab just the lines you want.

0 comments voice your opinion now!
tail system log file tutorial


blog comments powered by Disqus

Similar Posts

XpertDeveloper.com: PHP clearstatecache() Explained

Stoyan Stefanov's Blog: phpBB front-end optimization - 1 hour workshop

DevShed: Using the Xdebug Extension's xdebug_call_function() Function

Thomas Weinert: Basics: Using Arduino From PHP

UncleCode.com: Install PHPUnit Manually without Pear for a Single Project


Community Events











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


install facebook code component package language security performance unittest framework database hhvm composer release introduction threedevsandamaybe application podcast hack symfony2

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