PHP读取文件速度怎样优化,该怎么解决

WBOY
Release: 2016-06-13 12:22:49
Original
1094 people have browsed it

PHP读取文件速度怎样优化
各位前辈好,

小弟要读取一个大的log文件到该有一百六十万行
请问小弟改如何优化读文件的速度呢 ?

因为小弟要读取然后写进数据库。

小弟现在使用的fopen,fget这样来读。

请前辈赐教。
谢谢。
------解决思路----------------------

$fn = '文件名';<br />$fp = fopen($fn, 'r');<br />$last = '';<br />while(! feof($fp)) {<br />  $a = preg_split("/[\r\n]+/", $last . frenad($fp, 2048));<br />  for($i=0; $i<count($a)-1; $i++) {<br />     对数据的处理<br />  }<br />  $last = $a[$i];<br />}<br />if($last) 对数据的处理<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template