在Windows上的Apache / PHP的崩溃与常规的前pression [英] Apache / PHP on Windows crashes with regular expression

查看:280
本文介绍了在Windows上的Apache / PHP的崩溃与常规的前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现下面的PHP code崩溃当它运行在Windows Apache服务器上:

I have discovered that the following PHP code crashes when it runs on a Windows Apache server:

<?php

$test = "0,4,447,11329,316,415,142,5262,6001,9527,11259,11236,1140,9770,9177,9043,11090,268,5270,9907,9196,10226,".
        "9399,1476,9368,6929,1659,11074,10869,8774,739,11344,10482,6399,8910,8997,11198,137,10148,10371,5128,767,2483,".
        "211,9973,10726,9299,778,11157,9497,275,9418,11141,241,5288,11324,776,10960,9289,7944,222,10686,11428,9723,".
        "10615,11399,9869,9083,10180,10043,9957,9387,9215,8869,9667,10174,10902,6607,9282,1259,395,10411,152,9344,8949,".
        "10923,8976,11042,11519,10704,10979,216,10044,9201,1721,5831,881,9721,1757,11054,1335,6151,9526,9081,111,498,".
        "2960,438,5313,206,318,10820,8192,6039,9161,11012,1717,1360,10757,4314,11280,9647,9346,10546,11006,9553,10365,".
        "6148,10565,4532,2776,4124,8853,6145,478,4539,540,9981,726,7186,11122,324,10524,1139,7900,9581,6869,1724,10851,".
        "10059,10018,11032,1290,3818,782,796,917,8740,6935,11439,10799,10948,249,2068,8778,6289,295,2766,9425,791,309,".
        "4753,10418,771,260,10835,10441,6434,10164,10475,10842,9013,11224,2247,8972,2141,2078,2152,475,9077,6291,10285,".
        "8067,753,6660,10889,431,2503,6007,9180,810,11447,2461,3689,7104,10150,10921,895,10598,747,10570,305,4497,11055,".
        "11496,10938,10722,8761,10086,11482,6780,6685,6918,10286,10659,9996,4074,9118,907,5192,283,2230,8884,6966,".
        "8820,8132,3598,9599,6796,11257,7049,5992,8637,4168,9017,7950,7165,10721,10037,1071,8044,759,11429,6380,".
        "10239,1593,9455,9704,10357,6737,2958,4051,9754,6564,11407,8716,7485,1528,6857,7406,9579,7259,1609,7820,".
        "4448,10289,1123,7005,8123,9316,914,9655,5280,9710,7822,510,10795,10476,8706,6160,8248,6978,9300,10643,".
        "7106,10250,519,7860,4733,904,8773,4714,8695,8633,6105,3312,11548,9580,10389,4886,4587,513,8485,4606,".
        "6471,581,526,637,3523,3772,3153,9336,9120,7633,3755,10087,524,10015,8563,556,1230,570,3652,569"
        .",8473,10209,3886,573,5363,4715,3865,9452,1218,7066,575,577,4724,7655"
        ;

$hest = preg_match('/^\d+(?:,\d+)+$/', $test);
var_dump($hest);
?>

有趣的是,code工作如果字符串是一个短一点 - 如果我注释掉字符串时,code运行的最后一部分(线)和按预期工作

Interestingly enough, the code works if the string is a little shorter - if I comment out the last part (line) of the string, the code runs and works as expected.

不过,随着code是这里psented $ P $中,code导致Apache崩溃和重生 - 记录没有错误。如果我尝试运行code直接通过PHP它按预期工作,所以这个问题是某种联系到Apache。

However, as the code is presented here, the code causes Apache to crash and respawn - no error is logged. If I try to run the code directly through PHP it works as expected, so the problem is somehow related to Apache.

我已经尝试用pcre.recursion_limit设置,并发现,如果我降低这689它不会消失,而是在preg_match()调用失败,出现preG_RECURSION_LIMIT_ERROR。对于pcre.recursion_limit值较高的Apache死亡。

I have experimented with the "pcre.recursion_limit" setting, and found that if I lower this to 689 it doesn't die, but instead the preg_match() call fails with a PREG_RECURSION_LIMIT_ERROR. For higher values of pcre.recursion_limit Apache dies.

阿帕奇2.2.11
PHP 5.3.0

Apache 2.2.11 PHP 5.3.0

我还测试了这款Debian服务器,我没有看到的错误,并与不同版本的PHP和Apache在Windows上,在上述发生错误的,所以它似乎可能相关的Windows。

I have also tested this on a Debian server where I do NOT see the error, and with different versions of PHP and Apache on Windows, where the error occurs as described above, so it seems that it may be Windows related.

有任何人之前,这个作用似乎?我真的很想某种暗示!

Have anyone seens this before? I would really like a hint of some sort!

更新:我是因为在Apache的一个错误的Windows - 好吧,不是一个真正的错误,但似乎Apache正在用小STACKSIZE编译,而且导致此错误PCRE PHP时使用它。请参见 http://bugs.php.net/bug.php?id=47689

UPDATE: I is because of a "bug" in Apache for Windows - well, not really a bug, but it seems that Apache is compiled with a small stacksize, and that causes this error in PCRE when PHP uses it. See http://bugs.php.net/bug.php?id=47689

推荐答案

它总是一个好主意,以降低pcre.recursion_limit,因为默认的较高值会破坏进程栈(见的 http://php.net/manual/en/pcre.configuration.php ) - 这是什么情况您mod_php的安装。从什么时候开始递归/回溯限制达到preG功能不抛出一个错误,它可能是有用的,比如

It's always a good idea to lower "pcre.recursion_limit", because the default high value can corrupt the process stack (see http://php.net/manual/en/pcre.configuration.php) - this is exactly what happens with your mod_php install. Since preg functions don't throw an error when recursion/backtracking limits are reached, it may be useful to have a wrapper like

function match($re, $text) {
    preg_match($re, $text, $m);
    if(preg_last_error())
         trigger_error("preg: " . preg_last_error());
    return $m;
 }

至少,这可以让你知道出问题的时候。

At least, this lets you know when something goes wrong.

除此之外,尽量简化你的模式时可能的,例如 / ^ \\ D [\\ D,] * \\ D $ / 确实与上述相同,但零递归。

Besides that, try to simplify your patterns when possible, for example /^\d[\d,]*\d$/ does the same as above, but with zero recursion.

这篇关于在Windows上的Apache / PHP的崩溃与常规的前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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