Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This uses <code>fseek</code> to read 100 lines of a file starting from a specified offset. If the offset is greater than the number of lines in the log, the first 100 lines are read.</p> <p>In your application, you could pass the current offset through the query string for <em>prev</em> and <em>next</em> and base the next offset on that. You could also store and pass the current file position for more efficiency.</p> <pre><code>&lt;?php $GLOBALS["interval"] = 100; read_log(); function read_log() { $fp = fopen("log", "r"); $offset = determine_offset(); $interval = $GLOBALS["interval"]; if (seek_to_offset($fp, $offset) != -1) { show_next_button($offset, $interval); } $lines = array(); for ($ii = 0; $ii &lt; $interval; $ii++) { $lines[] = trim(fgets($fp)); } echo "&lt;pre&gt;"; print_r(array_reverse($lines)); } // Get the offset from the query string or default to the interval function determine_offset() { $interval = $GLOBALS["interval"]; if (isset($_GET["offset"])) { return intval($_GET["offset"]) + $interval; } return $interval; } function show_next_button($offset, $interval) { $next_offset = $offset + $interval; echo "&lt;a href=\"?offset=" . $offset . "\"&gt;Next&lt;/a&gt;"; } // Seek to the end of the file, then seek backward $offset lines function seek_to_offset($fp, $offset) { fseek($fp, 0, SEEK_END); for ($ii = 0; $ii &lt; $offset; $ii++) { if (seek_to_previous_line($fp) == -1) { rewind($fp); return -1; } } } // Seek backward by char until line break function seek_to_previous_line($fp) { fseek($fp, -2, SEEK_CUR); while (fgetc($fp) != "\n") { if (fseek($fp, -2, SEEK_CUR) == -1) { return -1; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload