PHP preg_match_all 100 MB文件 [英] PHP preg_match_all 100 MB file

查看:68
本文介绍了PHP preg_match_all 100 MB文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读到"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:

  1. 将变量 $ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆