Last active
December 24, 2015 02:09
-
-
Save victorjonsson/6728599 to your computer and use it in GitHub Desktop.
Tail -f but with PHP in a browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
$file = '/var/log/fpm/fpm-php.log'; | |
echo '<h5>'.$file.'</h5>'; | |
$offset = filesize($file) - 80240; | |
if( $offset < 0 ) | |
$offset = 0; | |
$file_content = file_get_contents($file, null, null, $offset) or die('Kunde inte öppna filen'); | |
$file_content = htmlentities($file_content); | |
echo str_replace(PHP_EOL, '<br>', $file_content); | |
?> | |
<script> | |
window.onload = function() { | |
window.scrollTo(0, document.height); | |
var stopReload = false; | |
window.addEventListener('scroll', function() { | |
stopReload = true; | |
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { | |
reloadSoon(); | |
} | |
}, false); | |
document.onmouseup = function() { | |
if( window.getSelection().type != "None" ) | |
stopReload = true; | |
}; | |
var reloadSoon = function() { | |
stopReload = false; | |
setTimeout(function() { | |
if( !stopReload ) | |
document.location.reload(); | |
}, 1000); | |
}; | |
reloadSoon(); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment