定制 icyapril/tail 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

icyapril/tail

Composer 安装命令:

composer require icyapril/tail

包简介

PHP library seeking to mimic the Unix tail program.

README 文档

README

Build Status Code Climate Test Coverage Issue Count

PHP Tail Library

A PHP Library for tailing files, supporting PHP 7.0 and above.

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.

Usage

Firstly let's create some random file with 3 lines of text.

$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:

$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:

Hello 2
Hello 3

Suppose we then append a line to the file:

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

Running getTail again will yield Hello 4:

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.

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

统计信息

  • 总下载量: 107
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-09-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固