This class can be used to 'tail' files. It's usage is not limited to *nix systems or access to the tail-command. You only have to have the permission to read the specified file. The class features the command 'grep' with that you can filter the output by keyword or regular expression. Take into account that some php-settings, like safemode and openbasedir, limit access to system-files.
require_once("class.tail.php");
$tailfile = isset($_REQUEST['file'])?urldecode($_REQUEST['file']):"./mail";
$mytail = new tail($tailfile);
instanciate new object of tail with name of file to tail
if (isset($_REQUEST['grep'])) {
$mytail->setGrep($_REQUEST['grep']);
set grep-keyword. for further usage of grep-feature, please read the comments in the code :)
}
if (isset($_REQUEST['show']) && is_numeric($_REQUEST['show'])){
$mytail->setNumberOfLines($_REQUEST['show']);
limit the lines to look at. if output is grep'ed, the grep only filters the last n lines, so the output would be less than that number of lines.
}
echo $mytail->output(HIGHLIGHT_BOLD+OL_LIST);
get output.
the class defines following constants:
further extensions are in planning.
I hope you find this class useful. For any hints and suggestions contact me at phpclasses.org