Solution for “Fatal error: Maximum function nestin

2019-01-01 00:46发布

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.

However, php returns this error:

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

ERROR

I found a solution here: Increasing nesting function calls limit but 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."

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

21条回答
梦寄多情
2楼-- · 2019-01-01 01:17

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

max_nesting_level is 100 by default

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's test before and after making this change to see if worked.

php -r 'function foo() { static $x = 1; echo "foo ", $x++, "\n"; foo(); } foo();'
查看更多
千与千寻千般痛.
3楼-- · 2019-01-01 01:18

If you're using Laravel, do

composer update

This should be work.

查看更多
梦该遗忘
4楼-- · 2019-01-01 01:19

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

ini_set('xdebug.max_nesting_level', 200);

查看更多
呛了眼睛熬了心
5楼-- · 2019-01-01 01:20

I had this issue with WordPress on cloud9. It turns out it was the W3 Caching plugin. I disabled the plugin and it worked fine.

查看更多
千与千寻千般痛.
6楼-- · 2019-01-01 01:20

Another solution if you are running php script in CLI(cmd)

The php.ini file that needs edit is different in this case. In my WAMP installation the php.ini file that is loaded in command line is:

\wamp\bin\php\php5.5.12\php.ini

instead of \wamp\bin\apache\apache2.4.9\bin\php.ini which loads when php is run from browser

查看更多
无与为乐者.
7楼-- · 2019-01-01 01:23

You could try to wiggle down the nesting by implementing parallel workers (like in cluster computing) instead of increasing the number of nesting function calls.

For example: you define a limited number of slots (eg. 100) and monitor the number of "workers" assigned to each/some of them. If any slots become free, you put the waiting workers "in them".

查看更多
登录 后发表回答