Last active
August 29, 2017 07:41
-
-
Save cornellsteven/a0ddca8d1b3dec373182 to your computer and use it in GitHub Desktop.
PHP / JS Tail
This file contains 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 | |
session_start(); | |
define('LOG', '/path/to/log/file'); | |
if (isset($_GET['ajax'])) { | |
$handle = fopen(LOG, 'r'); | |
fseek($handle, 0, SEEK_END); | |
$offset = ftell($handle); | |
if (isset($_SESSION['offset']) && $_SESSION['offset'] != $offset) { | |
$data = stream_get_contents($handle, -1, $_SESSION['offset']); | |
echo nl2br($data); | |
$_SESSION['offset'] = $offset; | |
} else { | |
$_SESSION['offset'] = $offset; | |
} | |
exit(); | |
} else { | |
unset($_SESSION['offset']); | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script> | |
<script src="//creativecouple.github.com/jquery-timing/jquery-timing.min.js"></script> | |
<script> | |
$(function() { | |
$.repeat(3000, function() { | |
$.get('?ajax', function(data) { | |
if ($('#tail').text() == 'Starting up...') { | |
$('#tail').html(''); | |
} | |
$('#tail').append(data); | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="tail">Starting up...</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment