<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Tue, 21 May 2013 02:22:45 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Sameer Borate's Blog: Tail functionality in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16606</guid>
      <link>http://www.phpdeveloper.org/news/16606</link>
      <description><![CDATA[<p>
<i>Sameer Borate</i> has posted <a href="http://www.codediesel.com/php/tail-functionality-in-php/">an alternative to "tail"</a> 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.
</p>
<blockquote>
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.
</blockquote>
<p>
His code opens a file pointer to the requested log, grabs the file size and uses the <a href="http://php.net/fseek">fseek</a> 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.
</p>]]></description>
      <pubDate>Tue, 19 Jul 2011 10:16:41 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Paul Gregg's Blog: "tail -# file" in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/12402</guid>
      <link>http://www.phpdeveloper.org/news/12402</link>
      <description><![CDATA[<p>
<i>Paul Gregg</i> has <a href="http://pgregg.com/blog/2009/04/tail---file-in-php.html">written up an example</a> of what he calls "tail -# file for PHP" (starting from the end of file and moving backwards a given number of lines).
</p>
<blockquote>
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.
</blockquote>
<p>
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 <a href="http://pgregg.com/projects/php/code/tail-10.phps">source here</a> and a <a href="http://pgregg.com/projects/php/code/tail-10.php">sample execution here</a>.
</p>]]></description>
      <pubDate>Fri, 24 Apr 2009 12:02:42 -0500</pubDate>
    </item>
  </channel>
</rss>
