2017 © Pedro Peláez
 

library tail

PHP library seeking to mimic the Unix tail program.

image

icyapril/tail

PHP library seeking to mimic the Unix tail program.

  • Monday, September 19, 2016
  • by IcyApril
  • Repository
  • 1 Watchers
  • 7 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status Code Climate Test Coverage Issue Count, (*1)

PHP Tail Library

A PHP Library for tailing files, supporting PHP 7.0 and above., (*2)

Currently, this library allows you to get the tail of a given file. Subsequent calls to the getTail function will return whatever has been appended since the last call., (*3)

Usage

Firstly let's create some random file with 3 lines of text., (*4)

$fileLocation = tempnam(sys_get_temp_dir(), 'tailTest');
file_put_contents($fileLocation, "Hello 1" . PHP_EOL . "Hello 2" . PHP_EOL . "Hello 3" . PHP_EOL);

Now we can instantiate the Tail Config class and inject it into the constructor of the Tail operator, then run the getTail function:, (*5)

$config = new \IcyApril\Tail\Config($fileLocation);
$config->setLines(2);

$tail = new \IcyApril\Tail\Tail($config);
echo $tail->getTail();

The output of this will be the final two lines of the file we created:, (*6)

Hello 2
Hello 3

Suppose we then append a line to the file:, (*7)

file_put_contents($fileLocation, "Hello 4" . PHP_EOL, FILE_APPEND | LOCK_EX);

Running getTail again will yield Hello 4:, (*8)

echo $tail->getTail();
// Hello 4

When to run getTail?

You can decide when to call the getTail function by either using the inotify watcher or simply using polling with the filemtime() function., (*9)

Caveats

  • The output is based on line count. If your file has 15 lines to start with, then has 17; the last 2 will be displayed at the next getTail call.
  • If a file is over-written and therefore has less than the amount of lines than it started with; the entire new file will be returned at the next getTail call.
  • Obviously you need to have your own polling/monitoring to decide when to call getTail

The Versions

19/09 2016

dev-master

9999999-dev

PHP library seeking to mimic the Unix tail program.

  Sources   Download

BSD-3-Clause

The Requires

  • php >7.0.0

 

The Development Requires

19/09 2016

v1.0

1.0.0.0

PHP library seeking to mimic the Unix tail program.

  Sources   Download

BSD-3-Clause

The Requires

  • php >7.0.0

 

The Development Requires