dou7851 2010-12-20 10:50
浏览 46
已采纳

foreach和preg_match对大量数据不能正常工作

I have to files, one is full of keywords sequences (~20k lines), the other is full of regular expression (~2.5k).

I want to test each keyword with each regexp and print the one that matches. I tested my files and that makes around 22 750 000 tests. I am using the following code :

$count = 0;
$countM = 0;
foreach ($arrayRegexp as $r) {
    foreach ($arrayKeywords as $k) {
        $count++;
        if (preg_match($r, $k, $match) {
            $countM++;
            echo $k.' matched with keywords '.$match[1].'<br/>';
        }
    }
}
echo "$count tests with $countM matches.";

Unfortunately, after computing for a while, only parts of the actual matches are displayed and the final line keeping the counts never displays. What is even more weird is that if I comment the preg section to keep only the two foreach and the count display, everything works fine.

I believe this is due to an excessive amount of data to be processed but I would like to know if there is recommendations I didn't follow for that kind of operations. The regular expressions I use are very complicated and I cannot change to something else.

Ideas anyone?

  • 写回答

2条回答 默认 最新

  • douzhannao5357 2010-12-20 11:04
    关注

    Increase execution time

    usethis line in .htaccess

    php_value max_execution_time 80000
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示