Smart autoscaling and monitoring for PHP-FPM applications
π Automatically optimize your PHP-FPM performance with intelligent scaling, real-time monitoring, and zero-downtime deployments.
This manager uses a dedicated configuration directory (/opt/phpfpm-runtime-manager/
) and does NOT modify your system's PHP-FPM configuration. This approach ensures your existing PHP-FPM setup remains untouched.
# Create dedicated directory:
sudo mkdir -p /opt/phpfpm-runtime-manager/
A production-ready tool that automatically manages your PHP-FPM worker processes based on real-time metrics. No more guessing optimal worker counts or manual performance tuning.
Perfect for:
- π’ Production websites that need consistent performance
- π High-traffic applications with variable load patterns
- π‘οΈ Enterprise environments requiring monitoring and compliance
- π¨βπ» DevOps teams wanting automated PHP-FPM management
- Automatically adjusts PHP-FPM worker count based on load
- Considers memory usage, CPU utilization, and queue depth
- Prevents over-provisioning and resource waste
- Live metrics dashboard with Prometheus integration
- Process-level tracking and performance insights
- Built-in health checks and alerting
- Graceful worker scaling without service interruption
- Rolling configuration updates
- Seamless deployment integration
- Multi-pool management for complex applications
- Audit logging and compliance features
- Role-based access control and API authentication
# Run with your existing PHP-FPM setup
docker run -d \
--name phpfpm-manager \
-p 8080:8080 \
-v /opt/phpfpm-runtime-manager:/opt/phpfpm-runtime-manager \
-v /var/run/php-fpm:/var/run/php-fpm \
cboxdk/phpfpm-runtime-manager:latest
# Download latest release
curl -L https://github.com/cboxdk/phpfpm-runtime-manager/releases/latest/download/phpfpm-manager-linux-amd64 -o phpfpm-manager
chmod +x phpfpm-manager
# Start with basic configuration
./phpfpm-manager run --config config.yaml
# Ubuntu/Debian
curl -s https://packagecloud.io/install/repositories/cboxdk/phpfpm-runtime-manager/script.deb.sh | sudo bash
sudo apt-get install phpfpm-runtime-manager
# CentOS/RHEL
curl -s https://packagecloud.io/install/repositories/cboxdk/phpfpm-runtime-manager/script.rpm.sh | sudo bash
sudo yum install phpfpm-runtime-manager
Create config.yaml
:
# Essential: PHP-FPM global configuration
phpfpm:
global_config_path: "/opt/phpfpm-runtime-manager/php-fpm.conf" # Dedicated config file
# Safe: Uses dedicated directory, doesn't modify system PHP-FPM config
server:
bind_address: "0.0.0.0:8080"
pools:
- name: "www"
config_path: "/opt/phpfpm-runtime-manager/pools.d/www.conf" # Individual pool config
fastcgi_endpoint: "127.0.0.1:9000" # How to reach this pool
max_workers: 20
scaling:
enabled: true
min_spare: 2
max_spare: 10
monitoring:
collect_interval: "10s"
storage:
database_path: "/var/lib/phpfpm-manager/data.db"
The manager uses a dedicated configuration directory and does NOT modify your system's PHP-FPM configuration:
# Create dedicated directory structure
sudo mkdir -p /opt/phpfpm-runtime-manager/pools.d/
# The manager creates all files in this structured directory:
# /opt/phpfpm-runtime-manager/
# βββ php-fpm.conf # Main PHP-FPM config
# βββ logs/ # All log files
# β βββ phpfpm-manager-error.log
# β βββ phpfpm-pool-*.log
# βββ pids/ # Process ID files
# β βββ phpfpm-manager.pid
# βββ sockets/ # Unix socket files (default)
# β βββ web.sock
# β βββ api.sock
# βββ pools.d/ # Individual pool configs
# βββ web.conf
# βββ api.conf
#
# Your system's /etc/php-fpm.conf remains untouched
Your individual pool configs (e.g., /opt/phpfpm-runtime-manager/pools.d/www.conf
) must have status enabled:
# In /opt/phpfpm-runtime-manager/pools.d/www.conf
pm.status_path = /status
ping.path = /ping
listen = 127.0.0.1:9000 # Must match fastcgi_endpoint in manager config
# Manager needs write access to its dedicated directory:
sudo chown -R phpfpm-manager:phpfpm-manager /opt/phpfpm-runtime-manager/
# Check overall system health
curl http://localhost:8080/health
# Get real-time metrics
curl http://localhost:8080/metrics
# View detailed pool information
curl http://localhost:8080/api/v1/pools
# Manually scale a pool
curl -X POST http://localhost:8080/api/v1/pools/www/scale \
-H "Content-Type: application/json" \
-d '{"workers": 15}'
# Enable/disable autoscaling
curl -X PATCH http://localhost:8080/api/v1/pools/www \
-H "Content-Type: application/json" \
-d '{"autoscaling_enabled": true}'
# Prometheus metrics endpoint
curl http://localhost:8080/metrics
# Grafana dashboard import
curl -L https://raw.githubusercontent.com/cboxdk/phpfpm-runtime-manager/main/examples/monitoring/grafana-dashboard.json
pools:
- name: "wordpress"
config_file: "/opt/phpfpm-runtime-manager/pools.d/wordpress.conf"
autoscaling:
enabled: true
min_workers: 4
max_workers: 50
scale_up_threshold: 80 # Scale up at 80% load
scale_down_threshold: 20 # Scale down at 20% load
memory:
limit_mb: 512
warning_threshold: 80
pools:
- name: "api"
config_file: "/opt/phpfpm-runtime-manager/pools.d/api.conf"
autoscaling:
enabled: true
min_workers: 2
max_workers: 20
- name: "web"
config_file: "/opt/phpfpm-runtime-manager/pools.d/web.conf"
autoscaling:
enabled: true
min_workers: 5
max_workers: 30
# Lightweight setup for development
server:
bind: "127.0.0.1:8080"
pools:
- name: "dev"
config_file: "/opt/phpfpm-runtime-manager/pools.d/dev.conf"
autoscaling:
enabled: false # Manual control during development
min_workers: 1
max_workers: 5
monitoring:
collect_interval: "30s" # Less frequent collection
storage:
type: "memory" # In-memory storage for dev
Pre-built dashboards available for:
- π Worker pool utilization
- πββοΈ Request processing times
- πΎ Memory usage patterns
- π¨ Error rates and alerts
Import dashboard: examples/monitoring/grafana-dashboard.json
Key metrics exposed:
phpfpm_workers_active # Currently active workers
phpfpm_workers_total # Total configured workers
phpfpm_requests_per_second # Request processing rate
phpfpm_memory_usage_bytes # Memory consumption
phpfpm_queue_length # Pending request queue
# Example alert for high queue length
- alert: PHPFPMHighQueue
expr: phpfpm_queue_length > 10
for: 2m
labels:
severity: warning
annotations:
summary: "PHP-FPM queue is backing up"
version: '3.8'
services:
web:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- php-fpm
- phpfpm-manager
php-fpm:
image: php:8.2-fpm-alpine
volumes:
- ./app:/var/www/html
- ./php-fpm.conf:/usr/local/etc/php-fpm.d/www.conf
phpfpm-manager:
image: cboxdk/phpfpm-runtime-manager:latest
ports:
- "8080:8080"
volumes:
- ./config.yaml:/etc/phpfpm-manager/config.yaml
- /var/run/php-fpm:/var/run/php-fpm
environment:
- LOG_LEVEL=info
apiVersion: apps/v1
kind: Deployment
metadata:
name: phpfpm-manager
spec:
replicas: 1
selector:
matchLabels:
app: phpfpm-manager
template:
metadata:
labels:
app: phpfpm-manager
spec:
containers:
- name: phpfpm-manager
image: cboxdk/phpfpm-runtime-manager:latest
ports:
- containerPort: 8080
env:
- name: CONFIG_PATH
value: "/etc/config/config.yaml"
volumeMounts:
- name: config
mountPath: /etc/config
- name: php-fpm-socket
mountPath: /var/run/php-fpm
server:
auth:
api_keys:
- key: "your-secret-api-key"
permissions: ["read", "write"]
basic_auth:
username: "admin"
password: "secure-password"
tls:
enabled: true
cert_file: "/path/to/cert.pem"
key_file: "/path/to/key.pem"
server:
rate_limiting:
enabled: true
requests_per_minute: 100
burst_size: 20
Manager can't connect to PHP-FPM
# Check PHP-FPM status endpoint is accessible
curl http://localhost/status?json
# Verify socket permissions
ls -la /var/run/php-fpm/
# Check manager logs
docker logs phpfpm-manager
Autoscaling not working
# Verify monitoring is collecting metrics
curl http://localhost:8080/api/v1/pools/www/metrics
# Check autoscaling configuration
curl http://localhost:8080/api/v1/pools/www
# Review scaling events in logs
tail -f /var/log/phpfpm-manager.log | grep "scaling"
High memory usage
# Check individual worker memory consumption
curl http://localhost:8080/api/v1/pools/www/workers
# Review memory limits in pool config
grep -r "pm.max_children\|memory_limit" /opt/phpfpm-runtime-manager/pools.d/
# Monitor memory trends
curl http://localhost:8080/metrics | grep phpfpm_memory
Optimize collection interval
monitoring:
collect_interval: "5s" # More responsive (higher CPU)
# or
collect_interval: "30s" # Less responsive (lower CPU)
Adjust scaling sensitivity
pools:
- name: "www"
autoscaling:
scale_up_threshold: 70 # Scale up sooner
scale_down_threshold: 30 # Scale down later
cooldown_period: "2m" # Wait between scaling events
Explore our comprehensive examples:
- π Basic Setup - Simple single-pool configuration
- π Full Featured - Complete configuration with all options
- π Docker - Ready-to-use Docker compose setup
- π Kubernetes - Production K8s deployment
- π High Memory - Memory-intensive application tuning
- π Multi-Pool - Multiple PHP applications
- π Installation Guide - Detailed setup instructions
- βοΈ Configuration Reference - Complete config options
- π§ API Documentation - REST API endpoints
- π‘οΈ Security Guide - Security best practices
- π¨βπ» Developer Guide - Contributing and development
- π Documentation: Comprehensive guides and references
- π¬ GitHub Discussions: Community Q&A and feature requests
- π Issue Tracker: Bug reports and technical issues
- π§ Enterprise Support: Commercial support and consulting
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ for the PHP community
β Star us on GitHub | π Documentation | π³ Docker Hub