baobao - 云代码空间
——
<?php error_reporting(0); set_time_limit(25200); $fp=fopen('vso_users.txt', "r"); $start_time = time(); while(!feof($fp)) { //每次读取128K if($data=fread($fp,1024*128)){ //格式化读取的数据 if(substr($data,-2) != "\n"){ //该块最后不为换行符时,将指针前移到最后一个换行符之后 $offset = strlen($data)-(strrpos($data,"\n")+1); if(!feof($fp)){ //文件未结束,则前移指针位置(保证读取内容的最后一行总是整行内容);若已读到文件结束位置则不移动文件指针位置。 fseek($fp,-$offset,SEEK_CUR); } //去掉最后一个换行符及其之后的内容 $data = substr($data,0,strrpos($data,"\n")); } if(substr($data,-2) == "\n"){ //去掉最后的换行符 $data = substr($data,0,strrpos($data,"\n")); } //单次取到的用户数组 $users = explode("\n",$data); //单次取到的行数 //$j+=(count($arr)); //echo count($users); } } $stop_time = time(); echo 'all users num: '.$totalcount.' user nums to delete: '.$usercount.' time used: '.($stop_time - $start_time).'s'; fclose($fp); ?>