php fseek 读取大文件处理

之前使用的是下面的代码

 1 <?php
 2 
 3 $time1 = microtime(true);
 4 $first_byte = memory_get_usage(); # 获取当前分配的内存
 5 
 6 $fhandler = fopen("wwchat.txt","r") or die("Can't not open file! ");
 7 
 8 if($fhandler){
 9     while(!feof($fhandler)){
10         $a = fgets($fhandler);
11         echo $a;
12     }
13     fclose($fhandler);
14 }
15 
16 $time2 = microtime(true);
17 
18 $second_byte = memory_get_usage();
19 echo "总的消耗内存".($second_byte - $first_byte)." byte";
20 echo "总的时间是".($time2 - $time1);
21 
22 # 总的消耗内存484 byte总的时间是0.13112115859985

fgets 

string fgets ( resource $handle [, int $length ] )

不带第二个参数 读取一行记录

fgetc 读取一个字符

string fgetc ( resource $handle ) 

读取一个字符 

慢慢沉淀自己
原文地址:https://www.cnblogs.com/martinding/p/7454040.html