Repository navigation
Make the hardcoded PHP memory_limit configurable - #13162
roshanprabu wants to merge 2 commits into
Conversation
app/init.php -- loaded by every Appwrite process (API, workers, CLI tasks) -- unconditionally hardcoded memory_limit to 512M with no way to override it. Uploading or processing files that approach this size crashes the process with "Allowed memory size of 536870912 bytes exhausted" (536870912 = exactly 512M), regardless of how much RAM the host actually has -- reproduced identically on hosts with 4GB and 64GB available. _APP_STORAGE_LIMIT (max upload size) is independently configurable and commonly raised well past 512MB for self-hosted large-file use cases, so this hardcoded ceiling silently undercuts a setting the operator already believes they've raised. Reads it from a new _APP_MEMORY_LIMIT env var instead, defaulting to the same 512M so existing deployments are unaffected. Verified the default is unchanged with the var unset, and that setting it to a larger value (e.g. 2048M) or -1 (unlimited) is honored by ini_get() after the call. Closes: appwrite#12643
Greptile SummaryThe PR makes the PHP memory limit configurable while preserving the existing 512M default.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported Docker Compose forwarding gap is fixed across all Appwrite PHP services. Important Files Changed
Reviews (2): Last reviewed commit: "Forward _APP_MEMORY_LIMIT into service c..." | Re-trigger Greptile |
| 'filter' => '' | ||
| ], | ||
| [ | ||
| 'name' => '_APP_MEMORY_LIMIT', |
There was a problem hiding this comment.
Compose drops the memory limit
When a self-hoster sets _APP_MEMORY_LIMIT through the repository's Docker Compose deployment, none of the Appwrite service environment blocks forward it into the containers, so app/init.php falls back to 512M and large uploads or memory-intensive jobs still hit the original limit.
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/config/variables.php
Line: 47
Comment:
**Compose drops the memory limit**
When a self-hoster sets `_APP_MEMORY_LIMIT` through the repository's Docker Compose deployment, none of the Appwrite service environment blocks forward it into the containers, so `app/init.php` falls back to `512M` and large uploads or memory-intensive jobs still hit the original limit.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.app/init.php reads _APP_MEMORY_LIMIT from the process environment, but none of the docker-compose.yml service environment blocks referenced it, so a self-hoster setting it in .env or their shell had nothing to carry it into the containers -- app/init.php always saw it unset and fell back to the 512M default regardless. Added it to the same 19 service blocks that already forward _APP_ENV, matching app/init.php's own scope (API entry point, queue workers, and CLI tasks -- i.e. every service that actually boots this bootstrap file, as opposed to infra containers like MariaDB/Redis that don't run Appwrite's PHP code at all).
|
Closing as stale since there has been no activity for a while. Thanks for the contribution! If this is still relevant, feel free to rebase on |
Summary
Fixes #12643.
app/init.php-- the bootstrap loaded by every Appwrite process (API, workers, CLI tasks) -- has:with no way to override it. The reported error is:
536870912bytes is exactly512M-- not a PHP default coincidence, this repo's own bootstrap sets it. The reporter's own testing confirms it's not a host resource issue: identical failure on a 4GB DigitalOcean droplet and a 64GB desktop VM with 12GB+ free throughout the upload.This is also an internal inconsistency:
_APP_STORAGE_LIMIT(max upload size,app/config/variables.php) is independently configurable and self-hosters commonly raise it well past 512MB for large-file use cases (the reporter tested 578MB and 1.3GB files). Raising_APP_STORAGE_LIMITalone doesn't help, since this separate, undocumented PHP-level ceiling silently caps what can actually be processed regardless.Fix
Read it from a new
_APP_MEMORY_LIMITenv var, documented inapp/config/variables.phpalongside the other_APP_*settings, defaulting to the same512Mso existing deployments see no behavior change unless they opt in:Self-hosters who raise
_APP_STORAGE_LIMITfor large files can now also raise this to match (or set it to-1to disable the limit entirely, standard PHPmemory_limitsyntax).Test plan
php -l, Pint, and PHPStan (level 4) pass on both changed files._APP_MEMORY_LIMITunset,ini_get('memory_limit')after the call is512M(unchanged default). With_APP_MEMORY_LIMIT=2048M, it's2048M. With_APP_MEMORY_LIMIT=-1, it's-1.