“致命错误:达到了'100'的最大函数嵌套级别,正在中止!”的解决方案 在 PHP 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8656089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:11:27  来源:igfitidea点击:

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

recursionxdebugphp

提问by Rafay

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 recursive and can go on endlessly. However, I have put a limit on the recursion by setting a global variable which causes the recursion to stop after 100 recursions.

我创建了一个函数,可以在一个 html 文件中查找所有 URL,并对链接到发现的 URL 的每个 html 内容重复相同的过程。该函数是递归的,可以无休止地运行。但是,我通过设置一个全局变量来限制递归,这会导致递归在 100 次递归后停止。

However, php returns this error:

但是,php 返回此错误:

Fatal error: Maximum function nesting level of '100' reached, aborting! in D:\wamp\www\crawler1\simplehtmldom_1_5\simple_html_dom.php on line 1355

致命错误:达到“100”的最大函数嵌套级别,正在中止!在 D:\wamp\www\crawler1\simplehtmldom_1_5\simple_html_dom.php 中的第 1355 行

ERROR

错误

I found a solution here: Increasing nesting function calls limitbut this is not working in my case.

我在这里找到了一个解决方案:增加嵌套函数调用限制,但这在我的情况下不起作用。

I am quoting one of the answers from the link mentioned above. Please do consider it.

我引用了上面提到的链接中的答案之一。请考虑一下。

"Do you have Zend, IonCube, or xDebug installed? If so, that is probably where you are getting this error from.

I ran into this a few years ago, and it ended up being Zend putting that limit there, not PHP. Of course removing it will let >you go past the 100 iterations, but you will eventually hit the memory limits."

“您是否安装了 Zend、IonCube 或 xDebug?如果是这样,那可能是您收到此错误的地方。

几年前我遇到了这个问题,最终是 Zend 把这个限制放在那里,而不是 PHP。当然,删除它会让 > 你超过 100 次迭代,但你最终会达到内存限制。”

Is there a way to increase the maximum function nesting level in PHP

有没有办法增加PHP中的最大函数嵌套级别

采纳答案by Rafay

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.inifile. This extension was limiting the stack to 100so I disabled it. The recursive function is now working as anticipated.

在我的php.ini文件中。这个扩展限制了堆栈,100所以我禁用了它。递归函数现在按预期工作。

回答by Maxence

Increase the value of xdebug.max_nesting_levelin your php.ini

增加xdebug.max_nesting_level你的价值php.ini

回答by Louis-Philippe Huberdeau

Rather than going for a recursive function calls, work with a queue model to flatten the structure.

与其使用递归函数调用,不如使用队列模型来扁平化结构。

$queue = array('http://example.com/first/url');
while (count($queue)) {
    $url = array_shift($queue);

    $queue = array_merge($queue, find_urls($url));
}

function find_urls($url)
{
    $urls = array();

    // Some logic filling the variable

    return $urls;
}

There are different ways to handle it. You can keep track of more information if you need some insight about the origin or paths traversed. There are also distributed queues that can work off a similar model.

有不同的方法来处理它。如果您需要了解有关原点或所经过路径的信息,您可以跟踪更多信息。还有分布式队列可以使用类似的模型。

回答by bacar ndiaye

Another solution is to add xdebug.max_nesting_level = 200in your php.ini

另一种解决方案是xdebug.max_nesting_level = 200在你的 php.ini添加

回答by shahinam

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

您可以设置更高的限制,而不是禁用 xdebug

xdebug.max_nesting_level=500

xdebug.max_nesting_level=500

回答by svassr

It's also possible to fix this directly in php, for example in the config file of your project.

也可以直接在 php 中修复此问题,例如在项目的配置文件中。

ini_set('xdebug.max_nesting_level', 200);

ini_set('xdebug.max_nesting_level', 200);

回答by Yasssine ELALAOUI

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

进入您的 php.ini 配置文件并更改以下行:

xdebug.max_nesting_level=100

to something like:

类似于:

xdebug.max_nesting_level=200

回答by Gujarat Santana

on Ubuntu using PHP 5.59 :
got to `:

在使用 PHP 5.59 的 Ubuntu 上:
到`:

/etc/php5/cli/conf.d

/etc/php5/cli/conf.d

and find your xdebug.iniin that dir, in my case is 20-xdebug.ini

并在该目录中找到您的xdebug.ini,在我的情况下是 20-xdebug.ini

and add this line `

并添加这一行`

xdebug.max_nesting_level = 200

xdebug.max_nesting_level = 200


or this


或这个

xdebug.max_nesting_level = -1

xdebug.max_nesting_level = -1

set it to -1 and you dont have to worry change the value of the nesting level.

将其设置为 -1,您不必担心更改嵌套级别的值。

`

`

回答by Lee Woodman

Try looking in /etc/php5/conf.d/ to see if there is a file called xdebug.ini

尝试查看 /etc/php5/conf.d/ 是否有名为 xdebug.ini 的文件

max_nesting_level is 100 by default

max_nesting_level 默认为 100

If it is not set in that file add:

如果未在该文件中设置,请添加:

xdebug.max_nesting_level=300

to the end of the list so it looks like this

到列表的末尾,看起来像这样

xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir=/home/drupalpro/websites/logs/profiler
xdebug.max_nesting_level=300

you can then use @Andrey'stest before and after making this change to see if worked.

然后,您可以在进行此更改之前和之后使用@Andrey 的测试来查看是否有效。

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

回答by vandersondf

probably happened because of xdebug.

可能是因为 xdebug 发生的。

Try commenting the following line in your "php.ini"and restart your server to reload PHP.

尝试在“php.ini”中注释以下行并重新启动服务器以重新加载 PHP。

? ";xdebug.max_nesting_level"

? ";xdebug.max_nesting_level"