0, "lines" => array("Failed to open log file. Check permissions!\n")))); } if(isset($_GET["offset"])) { $offset = intval($_GET['offset']); if($offset > 0) { // Seeks on the file pointer where we want to continue reading is known fseek($file, $offset); $lines = []; while (!feof($file)) array_push($lines, htmlspecialchars(fgets($file))); die(json_encode(array("offset" => ftell($file), "lines" => $lines))); } } // Locate the current position of the file read/write pointer fseek($file, -1, SEEK_END); // Add one to skip the very last "\n" in the log file die(json_encode(array("offset" => ftell($file)+1))); ?>