This script will tail a file using tail -F to follow scripts that are rotated.
<?php
$descriptorspec = array(
0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w") );
$filename = '/var/log/nginx/nginx-access.log';
if( !file_exists( $filename ) ) {
file_put_contents($filename, '');
}
$process = proc_open('tail -F /var/log/nginx/stats.bluebillywig.com-access.log', $descriptorspec, $pipes);
if (is_resource($process)) {
fclose( $pipes[0] );
stream_set_blocking($pipes[2], 0);
$count=0;
$stream = $pipes[1];
while ( ($buf = fgets($stream,4096)) ) {
print_r($buf);
$stderr = fread($pipes[2], 4096);
if( !empty( $stderr ) ) {
print( 'log: ' . $stderr );
}
}
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
}
?>