Increasing nesting function calls limit

2019-01-01 11:14发布

There is one very bad limit in PHP: if you call some function a1() that calls a2(), that calls a3... so when a99() will call a100() you will see

Fatal error: Maximum function nesting level of '100' reached, aborting!

Is there any way to increase the limit of 100 nesting calls to 500 or 10000?

This is critical for me because I'm developing an event-based system with a lot of callbacks.

标签: php xdebug
5条回答
还给你的自由
2楼-- · 2019-01-01 11:20

This error message comes specifically from the XDebug extension. PHP itself does not have a function nesting limit. Change the setting in your php.ini:

xdebug.max_nesting_level = 200

or in your PHP code:

ini_set('xdebug.max_nesting_level', 200);

As for if you really need to change it (i.e.: if there's a alternative solution to a recursive function), I can't tell without the code.

查看更多
旧人旧事旧时光
3楼-- · 2019-01-01 11:25

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.

查看更多
冷夜・残月
4楼-- · 2019-01-01 11:27

Yes, it's possible to increase the value of xdebug.max_nesting_level in php.ini. If you done this don't forget to restart the apache server:

sudo /usr/sbin/apachectl restart

But in most cases this error is not caused by that, but by many redirections or errors on your page.

So just switch to debug if you have one or watch your logs.

查看更多
查无此人
5楼-- · 2019-01-01 11:34

If you're using XDebug (with XAMPP, for example), you can set nesting level by adding this to php.ini file (I would suggest to put at the bottom of file):

[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
; Other settings if needed
xdebug.max_nesting_level = 500

This will set to 500 limit but it could more if needed. Only link to XDebug file php_xdebug.dll

查看更多
浪荡孟婆
6楼-- · 2019-01-01 11:40

Personally I would suggest this is an error as opposed to a setting that needs adjusting. In my code it was because I had a class that had the same name as a library within one of my controllers and it seemed to trip it up.

Output errors and see where this is being triggered.

查看更多
登录 后发表回答