逐行处理并截取数据写入新文件

<?php
/**
* 逐行处理并截取数据写入新文件
*/
ini_set('max_execution_time', '0');
$file = fopen("rabbit@hpayrabbitmq01.log.tar", "r") or exit("Unable to open file!");
$startTime = microtime(true);
while(!feof($file))
{
$line = fgets($file);
$rowStr = substr($line,0,10);
if ($rowStr == "2021-02-11") {
$path = "log.txt";
file_put_contents($path, $line, FILE_APPEND);
echo $line;
}
}
$totalTime = microtime(true) - $startTime;
echo "执行完毕,共计耗时---".$totalTime;
fclose($file);

?>