Repository navigation
feat(limits): raise PHP memory_limit automatically when a site runs out - #208
Merged
Merged
Conversation
The pool sets memory_limit as php_admin_value, so a site that genuinely needs more (Elementor editor, WooCommerce imports) cannot raise it itself and just dies with "Allowed memory size ... exhausted" until someone edits the limits card. Opt-in per hosting on the PHP-FPM & DB limits card, with a user-set ceiling (default 512 MB). The owning node reads what nginx appended to the site's error.log every two minutes (O_NOFOLLOW, inode/offset tracked, history skipped on first sight) and, on an OOM at the limit in force, raises the pool 128 MB, bounded by the ceiling and by node RAM (limit x max_children <= 3/4 MemTotal), with a 10-minute cooldown. Two quiet weeks step it back down, never below the operator's own value; turning it off restores that value. Raises notify (info); a site still OOMing at its ceiling warns once a day. A hand-typed memory value becomes the new floor; saving the card unchanged does not adopt the raised value as the floor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Opt-in automatic PHP
memory_limitper hosting. The owning node watches the site'slogs/error.logforAllowed memory size … exhausted. On an out-of-memory error at the limit in force, it raises the pool'smemory_limitone 128 MB step, but never above a user-set ceiling or what the node's RAM can hold. After two quiet weeks it steps back down, never below the operator's own value.Why
dluhopisar.cz (Elementor) keeps dying with
Allowed memory size of 268435456 bytes exhausted. The pool setsmemory_limitasphp_admin_value, soWP_MEMORY_LIMIT/ini_setcannot raise it. Until now the only fix was a manual edit of the limits card after someone noticed.Operator-facing change?
No operator-facing change.
Operator-facing change — described below:
Hosting → PHP-FPM & DB limits gains two controls. The first is the checkbox "Raise PHP memory automatically when the site runs out", which is off by default. The second is "Automatic ceiling" (MB, default 512, valid range 16–8192). A status line shows whether the limit has been raised from your value and when the site last ran out of memory.
How it behaves:
limit × max_childrenstays under ¾ of the node's RAM.New notifications (operator language, en + cs):
ops.php_mem_raised(info) on each raise.ops.php_mem_capped(warn, at most once a day) when the site still runs out at its ceiling.ops.php_mem_capped_ram(warn) when the node's RAM, not the ceiling, blocks a further raise.Audit entries:
php.mem_auto.raise,php.mem_auto.lowerandphp.mem_auto.restore.Notes for review
set_limitsresets the floor (base_mb) only when the memory value actually changes. The card shows the raised value, so saving it unchanged must not make that raised value the floor, or the limit would never come back down. The tick goes through the newstore_and_apply_limits, which never resets the floor.fs::read_appended, which opens it viaopen_no_follow. That function now also passesO_NONBLOCK, so a FIFO swapped in for the log is refused instead of hanging the open; this also applies to the existing log viewer. The reader tracks inode and offset, so rotation and truncation are handled. It reads at most 8 MiB per tick, holds back a half-written last line, and skips the existing history the first time it sees a log.hosting_kv(php.mem_auto,php.mem_auto_max_mb,php.mem_auto_state). No migration and no RPC change. An older node accepts the settings but does nothing with them.Test plan
cargo test --workspacepasses. Not run in full; the touched crates (types, adapters, core, web) all pass.cargo clippy --workspace --all-targetspasses (no new warnings).cargo fmt --all -- --checkpasses.phpmemunit tests: parser, stale-error filter, raise, cooldown, ceiling, RAM cap, alert throttle, lowering, ceiling lowered below the current limit.read_appendedtests: growth, partial line, truncation, burst larger than the read limit, symlink refused.php_mem_auto_raises_rebases_and_restores.Anti-scope
/wp-adminor the Elementor editor).🤖 Generated with Claude Code