New max_memory_limit INI setting

php.internals

Ilija Tovilo

1 year ago
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

Jordi Boggiano

1 year ago
On 14.04.2025 14:41, Ilija Tovilo wrote:
> 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

Tim Düsterhus

1 year ago
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