php-extended / php-tail
A smart way to tail files depending of the environment
7.0.7
2024-07-31 13:31 UTC
Requires
- php: >=8.0
- php-extended/php-system: ^7
Requires (Dev)
- dev-master
- 7.0.7
- 7.0.6
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.0.7
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.0.1
- 5.0.0
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.2.24
- 3.2.23
- 3.2.22
- 3.2.21
- 3.2.20
- 3.2.19
- 3.2.18
- 3.2.17
- 3.2.16
- 3.2.15
- 3.2.14
- 3.2.13
- 3.2.12
- 3.2.11
- 3.2.10
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.0.0
This package is auto-updated.
Last update: 2024-10-31 00:24:06 UTC
README
A smart way to tail files depending of the environment
Installation
The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.
- Download
composer.phar
from their website. - Then run the following command to install this library as dependency :
php composer.phar php-extended/php-tail ^7
Usage
The basic usage of this library is as follows :
use PhpExtended\Tail\Tail;
use PhpExtended\Tail\TailException;
$filename = "/../path/to/my/file.ext";
$tail = new Tail($filename);
try
{
// 10 is the number of lines you want
// 200 is the average number of chars on each line (optional)
// false is to force throwing exceptions (optional, use true if you want silent mode)
$lines = $tail->smart(10, 200, false);
}
catch(TailException $e)
{
// do something is case it fails
}
This library proposes 6 methods to tail a file, which can be more or less performant depending on the context. They each follow the same signature (see sample code above).
Those methods are :
naive
: Loads the whole file into php, then retains only the last linescheat
: Uses underlying unixtail -n
functionsingle
: Uses a signle byte buffer to read backwards the filesimple
: Uses a fixed size buffer to read backwards the filedynamic
: Uses a dynamically sized buffer to read backwards the filesmart
: Tries to choose the best among those five to be the fastest (recommanded)
This library is inspired from this specific stackoverflow topic.
License
MIT (See license file).