php-extended / php-tail
根据环境智能跟踪文件的智能方法
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-08-31 11:44:28 UTC
README
根据环境智能跟踪文件的智能方法
安装
此库的安装通过 composer 完成,所有类的自动加载都通过它们的自动加载器完成。
- 从他们的网站下载
composer.phar
。 - 然后运行以下命令将此库作为依赖项安装
php composer.phar require php-extended/php-tail ^7
使用方法
此库的基本用法如下
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
}
此库提供 6 种跟踪文件的方法,具体性能取决于上下文。它们遵循相同的签名(见上面的示例代码)。
这些方法包括:
naive
: 将整个文件加载到 php 中,然后仅保留最后几行cheat
: 使用底层的 Unixtail -n
函数single
: 使用单个字节缓冲区反向读取文件simple
: 使用固定大小的缓冲区反向读取文件dynamic
: 使用动态大小的缓冲区反向读取文件smart
: 尝试从这五种方法中选择最快的一种(推荐)
此库受此 特定 Stackoverflow 主题 启发。
许可
MIT(见 许可文件)。