Skip to content

Fix GH-17951: Addition of max_memory_limit INI #18011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix format specifiers to be platform specific
  • Loading branch information
frederikpyt committed Mar 10, 2025
commit 2d61446fe0001805435e8d6a53b602e0aa031a4a
30 changes: 26 additions & 4 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,20 @@ static PHP_INI_MH(OnChangeMemoryLimit)
if (value == -1 && PG(max_memory_limit) != -1) {
if (stage == ZEND_INI_STAGE_STARTUP) {
/* memory_limit exceeds max_memory_limit at INI parsing. */
zend_error_noreturn(E_ERROR, "memory_limit cannot be set to unlimited when max_memory_limit (%lld bytes) is not unlimited", PG(max_memory_limit));
zend_error(
E_ERROR,
"memory_limit cannot be set to unlimited when max_memory_limit (" ZEND_LONG_FMT " bytes) is not unlimited",
PG(max_memory_limit)
);
exit(1);
} else {
/* new memory_limit exceeds max_memory_limit at runtime. */
zend_error(E_WARNING, "Failed to set memory_limit to unlimited. memory_limit (currently: %lld bytes) cannot be set to unlimited if max_memory_limit (%lld bytes) is not unlimited", PG(memory_limit), PG(max_memory_limit));
zend_error(
E_WARNING,
"Failed to set memory_limit to unlimited. memory_limit (currently: " ZEND_LONG_FMT " bytes) cannot be set to unlimited if max_memory_limit (" ZEND_LONG_FMT " bytes) is not unlimited",
PG(memory_limit),
PG(max_memory_limit)
);
}

return FAILURE;
Expand All @@ -341,10 +351,22 @@ static PHP_INI_MH(OnChangeMemoryLimit)
if (PG(max_memory_limit) != -1 && value > PG(max_memory_limit)) {
if (stage == ZEND_INI_STAGE_STARTUP) {
/* memory_limit exceeds max_memory_limit at INI parsing. */
zend_error_noreturn(E_ERROR, "memory_limit (%zd bytes) exceeds max_memory_limit (%lld bytes)", value, PG(max_memory_limit));
zend_error(
E_ERROR,
"memory_limit (%zd bytes) exceeds max_memory_limit (" ZEND_LONG_FMT " bytes)",
value,
PG(max_memory_limit)
);
exit(1);
} else {
/* new memory_limit exceeds max_memory_limit at runtime. */
zend_error(E_WARNING, "Failed to set memory_limit to %zd bytes. memory_limit (currently: %lld bytes) cannot exceed max_memory_limit (%lld bytes)", value, PG(memory_limit), PG(max_memory_limit));
zend_error(
E_WARNING,
"Failed to set memory_limit to %zd bytes. memory_limit (currently: " ZEND_LONG_FMT " bytes) cannot exceed max_memory_limit (" ZEND_LONG_FMT " bytes)",
value,
PG(memory_limit),
PG(max_memory_limit)
);
}

return FAILURE;
Expand Down
Loading