Skip to content

Instantly share code, notes, and snippets.

@simbalinux
Created February 22, 2018 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbalinux/5b4cec2b8b29cc5f1f95d6bebefa15bb to your computer and use it in GitHub Desktop.
Save simbalinux/5b4cec2b8b29cc5f1f95d6bebefa15bb to your computer and use it in GitHub Desktop.
push last x lines of open file to new array
<?php
$lines=array();
$fp = fopen("../log/simplelogger.log", "r");
//tail off last x lines of the log file
while(!feof($fp))
{
$line = fgets($fp);
array_push($lines, $line);
if (count($lines)>10)
array_shift($lines);
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment