# Suggestion to increase the max_input_nesting_level

- Thread: https://externals.io/message/40386
- Original archive: https://news-web.php.net/php.internals/40386
- Started by Guilherme Blanco on 2008-09-09T00:50:30+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #40386 — Guilherme Blanco — 2008-09-09T00:50:30+00:00

URL: https://externals.io/message/40386#40386

Hi ML,


Short version: Increase the default max_input_nesting_level from 100
to something > 150.
Extended version:

I am working on a Compiler written for PHP. Before you criticize me,
let me explain the entire situation.
I work for Doctrine project. Currently we're refactoring the DQL
(Doctrine Query Language) compiler, which processes our SQL-similar
language and convert it into a valid SQL statement for the driver
being used.
If you want a comparative, our approach is inspired in known OQL, like
JPQL of Hibernate in Java.
One example:

SELECT u FROM User u

It'll be converted into something like:

SELECT u.id AS u__id, u.name AS u__name, u.passwd AS u_passwd, u.email
AS u__email FROM user u

Please notice this is a very simple example, but highlights how does it work.

Currently I'm working on the compiler, which has this BNF:
http://trac.doctrine-project.org/browser/trunk/query-language.txt
I've done a lot of optimizations to be able to not touch the default
nesting input level, but doing that I added a lot of restrictions that
now are my bottlenecks.
With all these optimizations, it currently reaches ~70.
I made a lot of tests and the queries usually reaches 103... some
complex ones reached ~140 nested calls.
I know PHP was not structured to build compilers, and also I know this
property can be overrided (many users do not have access to it), but I
think for this situation it worth a consideration.
Also, it's not a simple change for only one user, since our code usage
is very large.

My suggestion is to increase to something like 180, available since PHP 5.3.
I'd like to know your thoughts about this subject.

Thanks in advance,


Best regards,

-- 
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9166-6902
MSN: guilhermeblanco@hotmail.com
URL: http://blog.bisna.com
Rio de Janeiro - RJ/Brazil

---

## #40387 — Stanislav Malyshev — 2008-09-09T01:14:32+00:00

URL: https://externals.io/message/40386#40387 · In reply to: #40386

Hi!

> Currently I'm working on the compiler, which has this BNF:
> http://trac.doctrine-project.org/browser/trunk/query-language.txt
> I've done a lot of optimizations to be able to not touch the default
> nesting input level, but doing that I added a lot of restrictions that
> now are my bottlenecks.

I'm not sure I understand - how this compiler is related to input 
nesting level? What exactly you do there that requires 150+ levels of 
nesting on input?

-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #40388 — Guilherme Blanco — 2008-09-09T01:18:34+00:00

URL: https://externals.io/message/40386#40388 · In reply to: #40387

Each grammar rule may forward calls and subsequent things to build itself.

So, ConditionalExpression may forward a call and later call itself
again and again, etc.

At last, the number of nested function calls can easily reach 100.
If you need an example... I can spend some time on it to highlight to you.

Regards,


> Hi!
>
> > […]
>
> I'm not sure I understand - how this compiler is related to input nesting
> level? What exactly you do there that requires 150+ levels of nesting on
> input?
>
> --
> Stanislav Malyshev, Zend Software Architect
> stas@zend.com   http://www.zend.com/
> (408)253-8829   MSN: stas@zend.com
>



-- 
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9166-6902
MSN: guilhermeblanco@hotmail.com
URL: http://blog.bisna.com
Rio de Janeiro - RJ/Brazil

---

## #40389 — Stan Vassilev | FM — 2008-09-09T02:07:32+00:00

URL: https://externals.io/message/40386#40389 · In reply to: #40387

Hi,

He means recursion depth, not input nesting depth. 5.3 had a proposed fast 
function call algorithm which would avoid the stack limit and allow deeper 
recursion, was this accepted and how does it affect the limit of 100 nested 
calls?

Regards,
Stan Vassilev

> Hi!
>
> > […]
>
> I'm not sure I understand - how this compiler is related to input nesting 
> level? What exactly you do there that requires 150+ levels of nesting on 
> input?

---

## #40390 — Guilherme Blanco — 2008-09-09T02:57:01+00:00

URL: https://externals.io/message/40386#40390 · In reply to: #40389

Yeah... recursion depth.

Sorry, I wrongly typed it.

I think it may be cleaner now...

On Mon, Sep 8, 2008 at 11:07 PM, Stan Vassilev | FM
<sv_forums@fmethod.com> wrote:
>
> Hi,
>
> He means recursion depth, not input nesting depth. 5.3 had a proposed fast
> function call algorithm which would avoid the stack limit and allow deeper
> recursion, was this accepted and how does it affect the limit of 100 nested
> calls?
>
> Regards,
> Stan Vassilev
>
> > […]
>
>
> --
> 
> 
>
>



-- 
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9166-6902
MSN: guilhermeblanco@hotmail.com
URL: http://blog.bisna.com
Rio de Janeiro - RJ/Brazil

---

## #40396 — Derick Rethans — 2008-09-09T06:19:37+00:00

URL: https://externals.io/message/40386#40396 · In reply to: #40390

> Yeah... recursion depth.
> 
> Sorry, I wrongly typed it.
> 
> I think it may be cleaner now...

Well, PHP itself doesn't protect against this, but my guess is that you 
have Xdebug running. Xdebug limits to 100 levels by default in order to 
prevent infinite recursion and crashes. Change the 
xdebug.max_nesting_level setting to something higher and you'd be good 
to go.

regards,
Derick
-- 
HEAD before 5_3!: http://tinyurl.com/6d2esb
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org

---

## #40403 — Guilherme Blanco — 2008-09-09T13:12:19+00:00

URL: https://externals.io/message/40386#40403 · In reply to: #40396

Derick,

I do not have xdebug installed here.
That's why I thought it was something that could be changed, since
it's something too specific and afaik used only by xdebug.

Regards,


> 
>
> > […]
>
> Well, PHP itself doesn't protect against this, but my guess is that you
> have Xdebug running. Xdebug limits to 100 levels by default in order to
> prevent infinite recursion and crashes. Change the
> xdebug.max_nesting_level setting to something higher and you'd be good
> to go.
>
> regards,
> Derick
> --
> HEAD before 5_3!: http://tinyurl.com/6d2esb
> http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org
>



-- 
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9166-6902
MSN: guilhermeblanco@hotmail.com
URL: http://blog.bisna.com
Rio de Janeiro - RJ/Brazil

---

## #40404 — Scott MacVicar — 2008-09-09T13:19:38+00:00

URL: https://externals.io/message/40386#40404 · In reply to: #40403

There is no nesting limit, it recurses until it runs out of memory.
Derick was saying that XDebug will add one, but other than that there
isn't any.

dev/php53/sapi/cli/php -r 'function m($m) { echo ++$m . " "; m($m); }
m(0); '

I ran that and I got bored when it got to 750,000 levels deep.

Scott

Guilherme Blanco wrote:
> Derick,
> 
> I do not have xdebug installed here.
> That's why I thought it was something that could be changed, since
> it's something too specific and afaik used only by xdebug.
> 
> Regards,
> 
> 
> > […]

---

## #40405 — Guilherme Blanco — 2008-09-09T13:39:35+00:00

URL: https://externals.io/message/40386#40405 · In reply to: #40404

Hm...


Actually at that time I was not able to reproduce the limit, and I
wrote a fix that worked well and reduced the number of nest calls.
Maybe the guy that notified me was using it. Here is the changeset I
did to fix the issue: http://trac.phpdoctrine.org/changeset/4397

But right now I'll have to go back to add some scheduled support, and
I was afraid to fall into the same situation again, and I messaged the
list.

@Derick: If this is a xdebug specific, is there a way to you increase
this number?


Regards,


> There is no nesting limit, it recurses until it runs out of memory.
> Derick was saying that XDebug will add one, but other than that there
> isn't any.
>
> dev/php53/sapi/cli/php -r 'function m($m) { echo ++$m . " "; m($m); }
> m(0); '
>
> I ran that and I got bored when it got to 750,000 levels deep.
>
> Scott
>
> Guilherme Blanco wrote:
> > […]
>



-- 
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9166-6902
MSN: guilhermeblanco@hotmail.com
URL: http://blog.bisna.com
Rio de Janeiro - RJ/Brazil

---

## #40435 — Rodrigo Saboya — 2008-09-10T14:51:23+00:00

URL: https://externals.io/message/40386#40435 · In reply to: #40405

Guilherme Blanco wrote:
> Hm...
> 
> 
> Actually at that time I was not able to reproduce the limit, and I
> wrote a fix that worked well and reduced the number of nest calls.
> Maybe the guy that notified me was using it. Here is the changeset I
> did to fix the issue: http://trac.phpdoctrine.org/changeset/4397
> 
> But right now I'll have to go back to add some scheduled support, and
> I was afraid to fall into the same situation again, and I messaged the
> list.
> 
> @Derick: If this is a xdebug specific, is there a way to you increase
> this number?
> 
> 
> Regards,

Why? Running xdebug in production environments is not something people 
(should) do. And anyone using xdebug is probably smart enough to change 
a .ini setting to avoid what you are suggesting. Just add an entry to 
your FAQ / Manual about it.

--
Rodrigo Saboya
