PHP preg_match_all 100 MB文件 [英] PHP preg_match_all 100 MB file
问题描述
我已经读到"preg_match_all"不是用于解析大文件的,但是我需要这样做.我增加了:
I have read that "preg_match_all" is not made for parsing large files, but I need to do that. I have increased:
pcre.backtrack_limit=1000000000
pcre.recursion_limit=1000000000
我的PHP memory_limit设置为5000M,脚本仍在0.2秒内结束而没有任何错误或异常...
my PHP memory_limit is set to 5000M and script still ends without any error or exception within 0,2 sec...
唯一的解决方案是将100M文件分割成100个小的1M文件吗?
Is the only solutinon split the 100M file into 100 small 1M files?
感谢帮助
推荐答案
基于您的代码您可以这样操作:
Base on your code I suggest you to do it this way:
-
将变量
$ data
设置为空字符串
将变量 $ work
设置为空字符串;读取数据块并将此字符串附加到 $ data
Set variable $work
to empty string; read block of data and append this string to $data
使用正则表达式#^(.*?)(< tr> \ n(?!.*< tr> \ n).*)$#
拆分 $ data
到 $ work
和 $ data
Use regex #^(.*?)(<tr>\n(?!.*<tr>\n).*)$#
to split $data
to $work
and $data
在 $ work
在有数据可用时返回到第二点
Go back to point #2 while data available
在 $ data
这篇关于PHP preg_match_all 100 MB文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!