```
function getFile($filePath)
{
    $file = new \SplFileObject($filePath, 'r');
    if ($file) {
        while (!$file->eof()) {
            $line = $file->fgets();
            $encode = mb_detect_encoding($line, array("ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5'));
            $line = mb_convert_encoding($line, 'UTF-8', $encode);
            yield $line;
        }
    } else {
        return [];
    }
}

$lineCount = 0;
$tmpName = "test.log";
foreach (getFile($tmpName) as $key => $line) {
    echo $key. "\n";
}
```