Skip to content

Instantly share code, notes, and snippets.

@silasp
Forked from Firefishy/tail.php
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save silasp/7d6cb52c037d3c9ec7a1 to your computer and use it in GitHub Desktop.

Select an option

Save silasp/7d6cb52c037d3c9ec7a1 to your computer and use it in GitHub Desktop.
<?php
session_start();
if (!isset($_SESSION['offset'])) {
$_SESSION['offset'] = 0;
}
if (isset($_GET['ajax'])) {
$file = 'system.log';
$handle = fopen($file, 'r');
fseek($handle, 0, SEEK_END);
$eof_pos = ftell($handle);
if ($eof_pos != $_SESSION['offset']) {
$data = file_get_contents($file, NULL, NULL, $_SESSION['offset'] - 1);
$output = nl2br(preg_replace('/\n$/', '', $data, 1));
echo $output;
$_SESSION['offset'] = $eof_pos;
}
exit();
}
$_SESSION['offset'] = 0;
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://creativecouple.github.com/jquery-timing/jquery-timing.min.js"></script>
<script>
$(function() {
$.repeat(5000, function() {
$.get('tail.php?ajax', function(data) {
$('#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