PHP code example of reactphp-x / tail
1. Go to this page and download the library: Download reactphp-x/tail library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
reactphp-x / tail example snippets
eactphpX\Tail\Tail;
$tail = new Tail;
$tail->addPath('/var/log', ['*.log']);
$tail->addFile('/var/log/access.log');
$tail->start();
$filePath = '';
$tail->on('start', function ($file) use (&$filePath) {
if ($filePath != $file) {
$filePath = $file;
echo PHP_EOL . "==> " . $filePath . " <==" . PHP_EOL;
}
});
$tail->on('data', function ($data) {
echo $data;
});
$tail->on('end', function ($file) {
});