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() {
|
calculate_memory_per_process() {
|
||||||
local username="$1"
|
local username="$1"
|
||||||
|
|
||||||
local memory_stats
|
# Get average KB per process (single number)
|
||||||
memory_stats=$(get_fpm_memory_usage "$username")
|
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"
|
echo "0|0|0"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local avg_kb total_mb
|
# Calculate total memory in MB
|
||||||
avg_kb=$(echo "$memory_stats" | cut -d'|' -f1)
|
local total_mb
|
||||||
total_mb=$(echo "$memory_stats" | cut -d'|' -f2)
|
total_mb=$((avg_kb * process_count / 1024))
|
||||||
|
|
||||||
local process_count
|
|
||||||
process_count=$(get_fpm_process_count "$username")
|
|
||||||
|
|
||||||
echo "$avg_kb|$process_count|$total_mb"
|
echo "$avg_kb|$process_count|$total_mb"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -432,8 +432,8 @@ optimize_domain() {
|
|||||||
local pool_config
|
local pool_config
|
||||||
pool_config=$(find_fpm_pool_config "$username")
|
pool_config=$(find_fpm_pool_config "$username")
|
||||||
|
|
||||||
|
local current_max_children=""
|
||||||
if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then
|
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 ' ')
|
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
|
if [ -n "$current_max_children" ] && [ "$recommended_max_children" -ne "$current_max_children" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user