-
-
Save gamersalpha/ce937f940dce40f8f5545bb67cba3007 to your computer and use it in GitHub Desktop.
PHP log tail example
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 | |
if (isset($_GET['ajax'])) { | |
session_start(); | |
$handle = fopen('/private/var/log/system.log', 'r'); | |
if (isset($_SESSION['offset'])) { | |
$data = stream_get_contents($handle, -1, $_SESSION['offset']); | |
echo nl2br($data); | |
} else { | |
fseek($handle, 0, SEEK_END); | |
$_SESSION['offset'] = ftell($handle); | |
} | |
exit(); | |
} | |
?> | |
<!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(1000, 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