fgets无法完成读取错误日志 - php

时间:2015-11-19 17:45:46

标签: php readfile

我在下面尝试的简单方法是读取一个大的错误日志文件(35MB - 可能更大:),并过滤掉一些垃圾邮件我的日志,包含 x-mapp的行字符串。

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$handle = @fopen("error.log", "r");
if ($handle) {
    $i=0;
    while (($line = fgets($handle, 4096)) !== false) {
        if (strpos($line, 'x-mapp') !== FALSE){}
        else {
            echo $line.'<br>';
        }
        $i++;
    }

    if (!feof($handle)) {
       echo "Error: unexpected fgets() fail\n";
    }
    echo $i.' proccessed';
    fclose($handle);
} else {
    echo 'error';
} 

echo 'finished';

我得到的输出是这样的:

line-1 that doesn't contain x-mapp
line-2 that doesn't contain x-mapp
line-3 that doesn't contain x-mapp
line-4 that doesn't contain x-mapp

由于某些奇怪的原因,error.log文件的读取已停止,没有任何错误/警告。我会像这样输出:

line-1 that doesn't contain x-mapp
line-2 that doesn't contain x-mapp
line-3 that doesn't contain x-mapp
line-4 that doesn't contain x-mapp
Many more lines not containing x-map
782933 processed
finished

有什么想法吗?谢谢你的时间!

0 个答案:

没有答案