Fix 2 additional critical bugs in PHP scripts

BUG #7: php-optimizer.sh - Undefined variable in optimize_domain()
Location: modules/performance/php-optimizer.sh:507
Problem: Variable current_max_children was scoped inside if block (line 436)
         but used outside the if block (line 507), causing undefined variable
Solution: Moved declaration to line 435, before the if block
Impact: optimize_domain() would fail when trying to apply changes

BUG #8: php-analyzer.sh - calculate_memory_per_process() format mismatch
Location: lib/php-analyzer.sh:196-218
Problem: Function called get_fpm_memory_usage() expecting "kb|mb" format
         but get_fpm_memory_usage() returns only a single number (avg KB)
         This caused total_mb to always be empty
Solution: Fixed to:
  1. Accept single number from get_fpm_memory_usage()
  2. Get process_count separately
  3. Calculate total_mb = (avg_kb * process_count / 1024)
Impact: All memory calculations were wrong, showing 0 total memory

VERIFICATION:
- calculate_memory_per_process now correctly returns: avg_kb|count|total_mb
- optimize_domain can now access current_max_children when applying changes
- Memory statistics will show accurate values
This commit is contained in:
cschantz
2025-12-11 21:29:56 -05:00
parent 119bc6289a
commit f0ce29acd1
2 changed files with 13 additions and 10 deletions
+1 -1
View File
@@ -432,8 +432,8 @@ optimize_domain() {
local pool_config
pool_config=$(find_fpm_pool_config "$username")
local current_max_children=""
if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then
local current_max_children
current_max_children=$(grep "^pm.max_children" "$pool_config" | awk -F'=' '{print $2}' | tr -d ' ')
if [ -n "$current_max_children" ] && [ "$recommended_max_children" -ne "$current_max_children" ]; then