此PHP代码是否会使其他人的Apache崩溃? [英] Does this PHP code crash Apache for anyone else?

查看:97
本文介绍了此PHP代码是否会使其他人的Apache崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

preg_match_all('/(a)*/', str_repeat('a', 1000), $matches);

(稍微修改正则表达式以使其更简单,同时仍然崩溃)

(edit: change the regexp a bit to make it simpler while still crashing)

我在带有Apache 2.0的PHP 5.3.5上运行了它,它使服务器崩溃.如果我将339更改为338,则它不再崩溃,因此对我来说似乎是个错误.我尝试将其报告给 http://bugs.php.net/,但是它已关闭.这是一个PHP错误吗?它会崩溃吗?

I ran it on PHP 5.3.5 with Apache 2.0 and it crashes the server. If I change 339 to 338 it doesn't crash anymore, so it seems like a bug to me. I tried reporting it to http://bugs.php.net/ but it's down. Is this a PHP bug? Does it crash for anyone else?

编辑:将代码更改为

preg_match_all('/(?:a)*/', str_repeat('a', 339), $matches);

允许在崩溃前使用更长的字符串. 如果它没有崩溃,请尝试将字符串长度增加10或100倍,因为这可能是内存问题,并且您可能有更多内存.

allows for a longer string before crashing. If it doesn't crash, try increasing the string length by a factor of 10 or 100 as it may be a memory issue and you may have more memory.

崩溃是完全的进程崩溃,在Windows 7上,执行后我立即收到结束任务"消息.

Edit 2: the crash is a complete process crash, on Windows 7 I get the "End task" message instantaneously after execution.

:如果崩溃是由于回溯过多而导致的,而上面的示例显然可以导致崩溃,则以下内容不应导致这种情况:

Edit 3: if the crash is due to too much backtracing, and the above example clearly can cause it, the following should not:

preg_match('/[^"\']*(;|$)/',
               str_repeat('x', 1000), $matches);

这是我崩溃的实际代码.这仅意味着用;拆分多个SQL查询,同时允许在单引号或双引号内使用;.为什么这会造成大量回溯,我该如何解决?

This is my actual code that's crashing. It's simply meant to split multiple SQL queries by ;, while allowing ; inside single or double quotes. Why is this causing so much backtracing, and how can I fix it?

推荐答案

问题不是内存或执行时间...

The problem isn't memory or execution time...

ini_set('pcre.backtrack_limit', 10000);

如有必要,可以随意将10000 降低为其他值.有关更多信息,请参见 http://php.net/manual/en/pcre.configuration. php .

Feel free to decrease the 10000 to a different value if necessary. For more information, see http://php.net/manual/en/pcre.configuration.php.

如果您想测试崩溃的地方:

If you feel like testing where it crashes:

<?php

ini_set('pcre.backtrack_limit', 10000);

for ( $i = 1; $i < 65535; $i++ )
{
  echo $i . PHP_EOL;
  preg_match_all('/(a)*/', str_repeat('a', $i), $matches);
}

?>

这篇关于此PHP代码是否会使其他人的Apache崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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