dongliuxia9495
dongliuxia9495
2018-10-17 15:31

preg_replace_callback导致PHP死亡

  • php

I have a legacy text filter, which uses preg_replace_callback for parsing. However, when the parsed text is too complex, the code dies with no error message given, except for this PHP log entry WARNING: [pool www] child ... exited on signal 11.

To illustrate the problem, run the following code with values 10 and 20 in the $rows variable:

<?php

function my_callback(&$matches) {
    return $matches[0];
}

$regex = '#^\{\|(.*?)(?:^\|\+(.*?))?(^(?:((?R))|.)*?)^\|}#msi';

$columns = '';
$rows = 10; // 20 causes WSOD with no error given

for ($i=0; $i<20; $i++) {
  $columns .= "| style=\"width:6em\" | $i
";
}
$body = "{|
" . implode("|-
", array_fill(0, $rows, $columns)) . "
|}";

print preg_replace_callback($regex, 'my_callback', $body);

How do I increase the correcponding resource limit (assuming there is some) the code is hitting? Any help highly appreciated!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答