Solution for “Fatal error: Maximum function nesting level of '100' reached, aborting!” in PHP

后端 未结 22 2037
我寻月下人不归
我寻月下人不归 2020-11-22 16:45

I have made a function that finds all the URLs within an html file and repeats the same process for each html content linked to the discovered URLs. The function is recursiv

相关标签:
22条回答
  • 2020-11-22 17:06

    A simple solution solved my problem. I just commented this line:

    zend_extension = "d:/wamp/bin/php/php5.3.8/zend_ext/php_xdebug-2.1.2-5.3-vc9.dll
    

    in my php.ini file. This extension was limiting the stack to 100 so I disabled it. The recursive function is now working as anticipated.

    0 讨论(0)
  • 2020-11-22 17:07

    You can also modify the {debug} function in modifier.debug_print_var.php, in order to limit its recursion into objects.

    Around line 45, before :

    $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
      . '<b> -&gt;' . strtr($curr_key, $_replace) . '</b> = '
      . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
    

    After :

    $max_depth = 10;
    $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
      . '<b> -&gt;' . strtr($curr_key, $_replace) . '</b> = '
      . ($depth > $max_depth ? 'Max recursion depth:'.(++$depth) : smarty_modifier_debug_print_var($curr_val, ++$depth, $length));
    

    This way, Xdebug will still behave normally: limit recursion depth in var_dump and so on. As this is a smarty problem, not a Xdebug one!

    0 讨论(0)
  • 2020-11-22 17:09

    Rather than disabling the xdebug, you can set the higher limit like

    xdebug.max_nesting_level=500

    0 讨论(0)
  • 2020-11-22 17:09

    php.ini:

    xdebug.max_nesting_level = -1

    I'm not entirely sure if the value will ever overflow and reach -1, but it'll either never reach -1, or it'll set the max_nesting_level pretty high.

    0 讨论(0)
  • 2020-11-22 17:10

    Go into your php.ini configuration file and change the following line:

    xdebug.max_nesting_level=100
    

    to something like:

    xdebug.max_nesting_level=200
    
    0 讨论(0)
  • 2020-11-22 17:11

    Check recursion from command line:

    php -r 'function foo() { static $x = 1; echo "foo ", $x++, "\n"; foo(); } foo();'
    

    if result > 100 THEN check memory limit;

    0 讨论(0)
提交回复
热议问题