; ==============================================================================
; docker/php/www.conf — PHP-FPM Pool Configuration
; ==============================================================================
; Tuned for an SMM panel SaaS with moderate-to-high concurrent traffic.
; Rule of thumb: 1 worker per 25MB average memory usage.
; Monitor with: GET /up or php-fpm status page.

[www]
user = www-data
group = www-data

; ── Connection ────────────────────────────────────────────────────────────────
; Unix socket is faster than TCP for same-host Nginx ↔ PHP-FPM
listen = /run/php/php8.2-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

; ── Process Manager ───────────────────────────────────────────────────────────
; dynamic: spawn workers on demand, keep min idle, don't exceed max
; ondemand: spawn only when needed (lower baseline RAM, slower cold start)
; static: fixed number of workers (fastest, but wastes RAM if idle)
pm = dynamic

; Maximum simultaneous PHP requests
; Formula: (available RAM - system overhead) / PHP worker memory
; Example: 1GB server - 256MB OS = 768MB / ~50MB per worker = ~15 workers
pm.max_children = 20

; Workers to start when FPM starts
pm.start_servers = 4

; Minimum idle workers kept ready
pm.min_spare_servers = 2

; Maximum idle workers (excess are killed)
pm.max_spare_servers = 8

; ── Worker Recycling ──────────────────────────────────────────────────────────
; Restart workers after N requests to prevent memory leaks
; Set to 500 for Laravel (framework bootstraps cleanly)
pm.max_requests = 500

; ── Timeouts ──────────────────────────────────────────────────────────────────
request_terminate_timeout = 30s
request_slowlog_timeout = 5s
slowlog = /var/log/php/slow.log

; ── Status / Ping ─────────────────────────────────────────────────────────────
; Used by monitoring tools and healthchecks
pm.status_path = /fpm-status
ping.path = /fpm-ping
ping.response = pong

; ── Environment Passthrough ───────────────────────────────────────────────────
; Pass environment variables from Docker/system into PHP workers
clear_env = no
