<?php
$starttime=microtime_float();
ini_set('memory_limit', '-1');
$file = 'testfile.txt';
$data = file($file);
$line = $data[count($data) - 1000];
$endtime=microtime_float();
echo count($data),"<br/>";
echo $endtime-$starttime;
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
?>
<?php
$starttime=microtime_float();
$file = 'testfile.txt';
$file = escapeshellarg($file); // 对命令行参数进行安全转义
$line = `tail -n 100 $file`;
echo $line,"<br/>";
$endtime=microtime_float();
echo $endtime-$starttime;
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
//end
<?php
$starttime=microtime_float();
$file = 'testfile.txt';
$fp = fopen($file, "r+");
$line = 100;
$pos = -2;
$t =$data="";
while ($line > 0)
{
while ($t != "\n") //换行符
{
fseek($fp, $pos, SEEK_END);//移动指针
$t = fgetc($fp);//获取一个字符
$pos--;//向前偏移
}
$t = "";
$data = fgets($fp);//获取当前行的数据
$line--;
}
fclose($fp);
echo $data,"<br/>";
$endtime=microtime_float();
echo $endtime-$starttime;
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
?>
<?php
$starttime=microtime_float();
$file = 'testfile.txt';
$fp = fopen($file, "r");
$num = 10;
$chunk = 4096;//4K的块
$fs = sprintf("%u", filesize($file));
$readData='';
$max = (intval($fs) == PHP_INT_MAX) ? PHP_INT_MAX : $fs;
for($len = 0; $len < $max; $len += $chunk){
$seekSize = ($max - $len > $chunk) ? $chunk : $max - $len;
fseek($fp, ($len + $seekSize) * -1, SEEK_END);
$readData = fread($fp, $seekSize) . $readData;
if (substr_count($readData, "\n") >= $num + 1) {
$ns=substr_count($readData, "\n")-$num+2;
preg_match('/(.*?\n){'.$ns.'}/',$readData,$match);
$data = $match[1];
break;
}
}
fclose($fp);
echo $data,"<br/>";
$endtime=microtime_float();
echo $endtime-$starttime;
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
?>
<?php
$file = fopen("testfile.txt","r");
while(!feof($file))
{
echo fgets($file);
}
fclose($file);
<?php
try{
foreach( new SplFileObject('testfile.txt') as $line)
echo $line.'<br />';
}catch (Exception $e){
echo $e->getMessage();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有