PHP preg_match 在字符串中出现一定数量的字符时停止响应


PHP preg_match stops responding at certain number of characters in string

是否有某种PHP配置设置会影响传递到preg_match或preg_match_all的字符串的长度?

有以下内容,我正在尝试测试以找出我出了什么问题:

    $re = "/'['[section':(.*?)']']((.|'n)*?)'['[endsection']']/"; 
    $str = "[[section:body]]
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    [[endsection]]
    other stuff here"; 
    preg_match_all($re, $str, $matches);
    var_dump($matches);

现在,如果我运行它很好,它几乎会立即返回结果。

但是如果我在$str变量中添加一行并再次运行它,它只是旋转和旋转,然后我得到无法显示网页。

但是,如果我随后在 writecodeonline.com/php 上运行完全相同的东西,它可以正常工作并立即返回。

我的 php 错误日志或 apache 错误日志中没有收到任何错误,它只是在点击某些字符后拒绝执行任何操作(似乎一旦它达到 707 个字符它就会停止响应。

以前有人遇到过这种问题吗?只是我需要更改的一些配置设置吗?

干杯。

是的,有回溯限制

您可以在 php.ini 文件中配置它。

老实说,快速的谷歌搜索可以解决您的问题......