Created
September 5, 2019 08:46
-
-
Save jbrada/7324ca75bfebf415cbd04a6817d390e4 to your computer and use it in GitHub Desktop.
Large file DESC iteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
$file = fopen(__DIR__ . "/var/log/system.log", "r"); | |
$lineBuffer = ''; | |
for($characterPosition = 0; fseek($file, $characterPosition, SEEK_END) !== -1; $characterPosition--) { | |
$char = fgetc($file); | |
if ($char === PHP_EOL) { | |
echo $lineBuffer; | |
$lineBuffer = ''; | |
} | |
$lineBuffer = $char . $lineBuffer; | |
} | |
fclose($file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment