Skip to content

Instantly share code, notes, and snippets.

@antonorlov
Last active September 16, 2016 11:00

Revisions

  1. antonorlov revised this gist Sep 14, 2016. No changes.
  2. antonorlov created this gist Sep 14, 2016.
    31 changes: 31 additions & 0 deletions tail.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <?php
    if (isset($_GET['position'])) {
    $handle = fopen('/myfile.log', 'r');
    $content = stream_get_contents($handle, -1, intval($_GET['position']));
    fseek($handle, 0, SEEK_END);
    echo json_encode(array('position' => ftell($handle), 'content' => $content));
    exit();
    }
    ?>
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script>
    function tail(position = 0) {
    setTimeout(function () {
    $.getJSON('tail.php?position=' + position, function(data) {
    $('#tail').append(data.content);
    window.scrollTo(0, document.body.scrollHeight);
    tail(data.position);
    });
    }, 1000);
    }
    tail();
    </script>
    </head>
    <body>
    <pre id="tail"></pre>
    </body>
    </html>