Fix critical bug: never recommend 0 for pm.max_children in batch analyzer
ROOT CAUSE: The batch analyzer calls calculate_optimal_php_settings() which relies on calculate_max_children_memory_based(). When no active PHP-FPM processes exist (common in ondemand mode with sparse traffic), both functions returned 0. IMPACT: - Recommending pm.max_children: 0 (completely invalid, breaks PHP-FPM) - Causes silent failures in optimization reports - Especially problematic with ondemand PM mode + low traffic domains FIXES: 1. calculate_max_children_memory_based(): • When no processes detected: return 20 instead of 0 • When invalid parameters: return 20 instead of 0 2. calculate_optimal_php_settings(): • Added CRITICAL safety check: if final_max_children <= 0, use 20 • Ensures output is always safe regardless of calculation errors DEFAULTS: - Memory-based: 20 (safe minimum when no process data available) - Traffic-based: Uses actual peak concurrent if available - Safety guardrail: 20 minimum in all code paths This prevents invalid recommendations and ensures batch analyzer always provides sensible, actionable optimization guidance. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -84,7 +84,7 @@ calculate_max_children_memory_based() {
|
||||
local total_ram_mb="$2"
|
||||
|
||||
if [ -z "$total_ram_mb" ] || [ -z "$username" ]; then
|
||||
echo "0|Invalid parameters"
|
||||
echo "20|Invalid parameters"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -93,7 +93,9 @@ calculate_max_children_memory_based() {
|
||||
avg_kb=$(get_fpm_memory_usage "$username" 2>/dev/null || echo "0")
|
||||
|
||||
if [ "$avg_kb" -eq 0 ]; then
|
||||
echo "0|No active PHP-FPM processes found"
|
||||
# No active processes detected (ondemand mode, or low traffic)
|
||||
# Use safe default: 20 processes with assumed 50MB per process
|
||||
echo "20|No active processes, using safe default"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -369,6 +371,12 @@ calculate_optimal_php_settings() {
|
||||
reason_prefix="Combined (memory: $memory_based_max, traffic: $traffic_based_max)"
|
||||
fi
|
||||
|
||||
# CRITICAL: Ensure we never recommend 0 or invalid values
|
||||
if [ -z "$final_max_children" ] || [ "$final_max_children" -le 0 ]; then
|
||||
final_max_children="20"
|
||||
reason_prefix="Safe default (calculation failed or returned invalid value)"
|
||||
fi
|
||||
|
||||
# Recommend pm mode
|
||||
local pm_result
|
||||
pm_result=$(recommend_pm_mode "$peak_concurrent" "$((peak_concurrent / 2))" "$stability_factor")
|
||||
|
||||
Reference in New Issue
Block a user