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:
+12
-9
@@ -199,20 +199,23 @@ analyze_execution_timeout_errors() {
|
||||
calculate_memory_per_process() {
|
||||
local username="$1"
|
||||
|
||||
local memory_stats
|
||||
memory_stats=$(get_fpm_memory_usage "$username")
|
||||
# Get average KB per process (single number)
|
||||
local avg_kb
|
||||
avg_kb=$(get_fpm_memory_usage "$username")
|
||||
|
||||
if [ -z "$memory_stats" ] || [[ "$memory_stats" == "0|0" ]]; then
|
||||
# Get process count
|
||||
local process_count
|
||||
process_count=$(get_fpm_process_count "$username")
|
||||
|
||||
# Check if no processes found
|
||||
if [ -z "$avg_kb" ] || [ "$avg_kb" -eq 0 ] || [ "$process_count" -eq 0 ]; then
|
||||
echo "0|0|0"
|
||||
return
|
||||
fi
|
||||
|
||||
local avg_kb total_mb
|
||||
avg_kb=$(echo "$memory_stats" | cut -d'|' -f1)
|
||||
total_mb=$(echo "$memory_stats" | cut -d'|' -f2)
|
||||
|
||||
local process_count
|
||||
process_count=$(get_fpm_process_count "$username")
|
||||
# Calculate total memory in MB
|
||||
local total_mb
|
||||
total_mb=$((avg_kb * process_count / 1024))
|
||||
|
||||
echo "$avg_kb|$process_count|$total_mb"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user