cschantz
|
7c550ebeb0
|
Phase 2: Add comprehensive PHP analysis engine (lib/php-analyzer.sh)
ANALYSIS CAPABILITIES (12 functions):
- Error log analysis (memory exhausted, max_children, timeouts, slow requests)
- Resource usage calculations (memory per process, optimal max_children)
- Traffic analysis (peak concurrent requests, avg requests/minute)
- OPcache effectiveness analysis (hit rate, memory usage, recommendations)
- Configuration issue detection (security, performance, capacity issues)
- Complete domain analysis reporting
ERROR LOG ANALYSIS:
- analyze_memory_exhausted_errors: Track "Allowed memory size exhausted"
- analyze_max_children_errors: Detect "server reached pm.max_children" (CRITICAL!)
- analyze_slow_requests: Parse slow request logs, track slowest scripts
- analyze_execution_timeout_errors: Find "Maximum execution time exceeded"
RESOURCE CALCULATIONS:
- calculate_memory_per_process: Average KB per PHP-FPM process
- calculate_optimal_max_children: Intelligent calculation based on:
* Available system memory (total - reserved)
* Average memory per process
* 20% safety buffer
* Minimum sanity checks
TRAFFIC ANALYSIS:
- calculate_peak_concurrent_requests: Peak concurrent from access logs
- calculate_avg_requests_per_minute: Average load over time period
OPCACHE ANALYSIS:
- analyze_opcache_effectiveness: Status, hit rate, memory usage, recommendations
* Detects if disabled (40-70% perf loss!)
* Calculates hit rate (should be >90%)
* Checks wasted memory and cache capacity
ISSUE DETECTION (7 critical checks):
- detect_php_config_issues: Comprehensive configuration validation
1. post_max_size < upload_max_filesize (CRITICAL - uploads fail)
2. display_errors = On (HIGH - security risk)
3. memory_limit too low (MEDIUM - performance issue)
4. pm.max_children errors (CRITICAL - capacity issue)
5. Memory exhausted errors (HIGH - need more RAM or optimization)
6. OPcache disabled or low hit rate (HIGH/MEDIUM - performance)
7. pm.max_requests = 0 (MEDIUM - memory leaks accumulate)
8. pm = static on low traffic (LOW - wastes memory)
COMPREHENSIVE REPORTING:
- analyze_domain_php: Complete analysis report including:
* PHP version detection
* Configuration hierarchy (4 priority levels)
* Effective settings (memory, execution, uploads)
* PHP-FPM pool configuration
* Resource usage (processes, memory)
* OPcache status and hit rates
* Traffic analysis (24h)
* Error analysis (7 days)
* Issues detected with severity levels
* Optimization recommendations with reasoning
HELPER FUNCTIONS:
- convert_to_bytes: Parse human-readable sizes (128M → bytes)
INTEGRATION:
- Uses lib/php-detector.sh for all detection
- Uses lib/system-detect.sh for system info
- All functions exported for use by main optimizer
NEXT PHASE: modules/performance/php-optimizer.sh (interactive menu + apply changes)
|
2025-12-02 20:28:27 -05:00 |
|