Skip to content

ADR-002: PHP Cron/Worker memory_limit Capped at 1G

Status

Accepted

Context

The Friendica worker daemon (cron container) processes federation tasks including fetching ActivityPub reply collections from remote Mastodon/Pleroma instances. Some instances return multi-GB JSON responses via Guzzle HTTP.

With memory_limit=4G (previously tried at 8G), PHP slowly allocated memory up to the limit before crashing with a Fatal Error. This caused 6.81 TB block writes and 2000+ writes/s I/O spikes on the NVMe RAID from an infinite crash-loop.

Decision

Cap memory_limit at 1G for all cron/worker containers (cron.ini, friendica.ini, opensocial.ini). FPM pools use 512M (app.ini).

Note (2026-03-01): The PHP ini memory_limit is now 2G at the process level — Friendica's per-task worker_memory_limit (default 512 MiB via ini_set) still caps individual tasks. The I/O crash scenario only applies when worker_memory_limit is absent.

Consequences

  • ✅ Crashes are fast — only ~1G of pages touched before crash
  • ✅ The worker supervisor marks the job as failed and moves on
  • ✅ NVMe write amplification reduced by orders of magnitude
  • ⚠️ Legitimate large operations that need >1G will fail (none observed in practice)
  • ⚠️ Root cause (remote instances returning multi-GB responses) is not fixed
  • 🔗 See: services/friendica-opensocial.md for current PHP memory configuration details