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.

Revisions

  1. silasp revised this gist Sep 1, 2014. 1 changed file with 32 additions and 25 deletions.
    57 changes: 32 additions & 25 deletions tail.php
    Original file line number Diff line number Diff line change
    @@ -1,37 +1,44 @@
    <?php
    session_start();
    if (!isset($_SESSION['offset'])) {
    $_SESSION['offset'] = 0;
    }

    if (isset($_GET['ajax'])) {
    $sessionID = 'log'.$_GET['s'];
    session_id($sessionID);
    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 {

    $file = 'system.log';
    $handle = fopen($file, 'r');
    fseek($handle, 0, SEEK_END);
    }
    $_SESSION['offset'] = ftell($handle);
    exit();
    $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();
    }
    $randomSession = rand();

    $_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(1000, function() {
    $.get('tail.php?ajax&s=<?=$randomSession;?>', function(data) {
    $('#tail').append(data);
    });
    });
    });
    </script>
    <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>
    <div id="tail">Starting up...</div>
    </body>
    </html>
  2. @Firefishy Firefishy revised this gist Jul 24, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tail.php
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@
    <script>
    $(function() {
    $.repeat(1000, function() {
    $.get('tail.php?ajaxs&s=<?=$randomSession;?>', function(data) {
    $.get('tail.php?ajax&s=<?=$randomSession;?>', function(data) {
    $('#tail').append(data);
    });
    });
  3. @Firefishy Firefishy revised this gist Jul 24, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions tail.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    <?php
    if (isset($_GET['ajax'])) {
    $sessionID = 'log'.$_GET['s'];
    session_id($sessionID);
    session_start();
    $handle = fopen('/private/var/log/system.log', 'r');
    if (isset($_SESSION['offset'])) {
  4. @Firefishy Firefishy revised this gist Jul 24, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions tail.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    <?php
    if (isset($_GET['ajax'])) {
    $sessionID = 'log'.$_GET['s'];
    session_start();
    $handle = fopen('/private/var/log/system.log', 'r');
    if (isset($_SESSION['offset'])) {
    @@ -10,7 +11,8 @@
    }
    $_SESSION['offset'] = ftell($handle);
    exit();
    }
    }
    $randomSession = rand();
    ?>
    <!doctype html>
    <html lang="en">
    @@ -21,7 +23,7 @@
    <script>
    $(function() {
    $.repeat(1000, function() {
    $.get('tail.php?ajax', function(data) {
    $.get('tail.php?ajaxs&s=<?=$randomSession;?>', function(data) {
    $('#tail').append(data);
    });
    });
  5. @Firefishy Firefishy revised this gist Jul 24, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tail.php
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@
    echo nl2br($data);
    } else {
    fseek($handle, 0, SEEK_END);
    $_SESSION['offset'] = ftell($handle);
    }
    $_SESSION['offset'] = ftell($handle);
    exit();
    }
    ?>
  6. Chris Burke created this gist Oct 6, 2012.
    34 changes: 34 additions & 0 deletions tail.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    <?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>