Skip to content

Instantly share code, notes, and snippets.

@bosunski
Created November 17, 2018 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bosunski/af059302599436de2f473ff800056592 to your computer and use it in GitHub Desktop.
Save bosunski/af059302599436de2f473ff800056592 to your computer and use it in GitHub Desktop.
<?php
$fileCache = "LastLine.txt";
$oldLastLine = getLastLine($fileCache);
function getLastLine($cachePath)
{
if (file_exists($cachePath))
return file_get_contents($cachePath);
return 0;
}
function fileRead($path) {
$fileHandle = fopen($path, 'rb');
while (($line = fgets($fileHandle)) !== false) {
yield rtrim($line, "\r\n");
}
fclose($fileHandle);
}
$lastLine = 0;
$updates = "";
foreach (fileRead(".gitignore") as $line) {
$lastLine++;
if ($lastLine > $oldLastLine) {
$updates .= $line . PHP_EOL;
}
}
file_put_contents($fileCache, $lastLine);
echo $updates;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment