1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#!/usr/bin/php
<?php
/**
* This example can be used to logfile processing and basically wraps the tail
* command.
*
* The benefit of using this, is that it allows you to tail multiple logs at
* the same time
*
* To stop this application, hit CTRL-C
*/
if ($argc < 2) {
echo "Usage: " . $argv[0] . " filename\n";
exit(1);
}
require 'Sabre/Event/autoload.php';
$tail = popen('tail -fn0 ' . escapeshellarg($argv[1]), 'r');
\Sabre\Event\Loop\addReadStream($tail, function() use ($tail) {
echo fread($tail, 4096);
});
\Sabre\Event\Loop\run();
|