Barryvdh\Debugbar\DataCollector\LogsCollector::tailFile PHP Method

tailFile() protected method

By Ain Tohvri (ain) http://tekkie.flashbit.net/php/tail-functionality-in-php
protected tailFile ( string $file, integer $lines ) : array
$file string
$lines integer
return array
    protected function tailFile($file, $lines)
    {
        $handle = fopen($file, "r");
        $linecounter = $lines;
        $pos = -2;
        $beginning = false;
        $text = [];
        while ($linecounter > 0) {
            $t = " ";
            while ($t != "\n") {
                if (fseek($handle, $pos, SEEK_END) == -1) {
                    $beginning = true;
                    break;
                }
                $t = fgetc($handle);
                $pos--;
            }
            $linecounter--;
            if ($beginning) {
                rewind($handle);
            }
            $text[$lines - $linecounter - 1] = fgets($handle);
            if ($beginning) {
                break;
            }
        }
        fclose($handle);
        return array_reverse($text);
    }