# New max_memory_limit INI setting

- Thread: https://externals.io/message/127108
- Original archive: https://news-web.php.net/php.internals/127108
- Started by Ilija Tovilo on 2025-04-14T12:41:50+00:00
- Messages: 3
- 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

---

## #127108 — Ilija Tovilo — 2025-04-14T12:41:50+00:00

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

Hi everyone

We've received a PR from Frederik Pytlick (@frederikpyt, thank you!)
that introduces a new max_memory_limit INI setting.

https://github.com/php/php-src/pull/18011

This setting declares an upper bound for memory_limit, which will
prevent memory_limit from being set to a value higher than
max_memory_limit, resulting in a warning (currently an error on
startup, but I think this should be changed). It defaults to -1, which
is unlimited. While memory_limit can be set at runtime,
max_memory_limit is limited to startup. This may be useful to prevent
3rd party libraries from setting the limit unreasonably high.
Similarly, it may declare an upper bound in shared hosting
environments.

One open question is whether exceeding the max_memory_limit should
also set memory_limit to max_memory_limit in addition to warning,
giving the subsequent operation a higher chance not to straight out
OOM error. Let me know if you have a preference in that regard.

This seems like a reasonable addition, allowing for more granular
memory limit control. Let me know if you have any thoughts or
concerns. If not, I'm planning to merge this PR into master in a
couple of weeks.

Ilija

---

## #127111 — Jordi Boggiano — 2025-04-15T08:13:17+00:00

URL: https://externals.io/message/127108#127111 · In reply to: #127108

> One open question is whether exceeding the max_memory_limit should
> also set memory_limit to max_memory_limit in addition to warning,
> giving the subsequent operation a higher chance not to straight out
> OOM error. Let me know if you have a preference in that regard.

I'd say absolutely yes it should respect the requested memory limit as 
much as possible.

Especially when setting memory_limit to -1 you'd definitely want this to 
mean "use the max allowed memory limit" and perhaps even skip the 
warning in that case as it's not a very specific request for a memory 
amount.

Best,
Jordi

-- 
Jordi Boggiano
@seldaek -https://seld.be

---

## #127127 — tim@bastelstu.be — 2025-04-17T07:36:30+00:00

URL: https://externals.io/message/127108#127127 · In reply to: #127111

Hi

Am 2025-04-15 10:13, schrieb Jordi Boggiano:
> I'd say absolutely yes it should respect the requested memory limit as 
> much as possible.
> 
> Especially when setting memory_limit to -1 you'd definitely want this 
> to mean "use the max allowed memory limit" and perhaps even skip the 
> warning in that case as it's not a very specific request for a memory 
> amount.

I agree with Jordi's entire email.

Best regards
Tim Düsterhus
