【发布时间】:2015-05-16 14:14:21
【问题描述】:
是否有某种 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 strong> 停止响应的字符。
以前有人遇到过这种问题吗?只是我需要更改一些配置设置吗?
干杯。
【问题讨论】:
-
要补充这一点,下面建议的 php.ini 设置没有帮助。同样的问题仍在发生。我已经尝试对脚本进行 webgrind 配置文件以查看发生了什么,但是一旦它达到字符串中的 695 个字符,它甚至不会创建配置文件输出,它是空的,并且脚本什么都不做,除了坐在那里旋转大约20秒左右。然而从字符串中删除一个字符,结果是即时的。
-
这似乎是完全相同的问题:forum.wampserver.com/read.php?2,65936,65946 我也在 WAMP 服务器上,我的问题与那些人的行为完全相同
-
使用以下信息解决了这个问题:stackoverflow.com/questions/7620910/… 基本上 pcre.recursion_limit 的默认设置 100000 太高,导致(我认为)堆栈溢出,导致 apache 崩溃并导致它重新启动,这解释了我的 apache 错误日志中没有错误,但重新启动通知。根据该问题中的说明,我将 WAMP 安装更改为 524。
标签: php regex preg-match