Compare commits

...

3 Commits

Author SHA1 Message Date
Developer ff8c01a169 CRITICAL FIX: Correct MySQL memory field extraction
The calculate_server_capacity() function was extracting the wrong
field from detect_mysql_memory_usage(), causing incorrect available
memory calculations and resulting in 0 max_children recommendations.

Bug: Was extracting field 1 (buffer_pool_mb)
Fix: Now extracts field 3 (estimated_total_mb - actual usage)

detect_mysql_memory_usage returns: buffer_pool|connections|total_mb|status

This fix allows Level 5 optimization to correctly calculate PHP-FPM
capacity and make proper recommendations instead of recommending 0.
2026-04-20 22:16:34 -04:00
Developer a4adf9a398 FIX: Add timeouts to MySQL detection to prevent hanging
The calculate_server_memory_capacity() function was hanging during
optimization levels 1-4 because of unguarded MySQL queries.

Fixed:
1. Added 2-second timeout to MySQL queries in detect_mysql_memory_usage()
   - Lines 1395-1396: buffer_pool_mb and max_connections queries
   - These would hang indefinitely if MySQL was slow or unresponsive

2. Added 5-second timeout to detect_mysql_memory_usage() call
   - Line 1008 in calculate_server_memory_capacity()
   - Prevents the entire function from blocking

This allows optimization levels 1-5 to execute without hanging
when MySQL is unavailable or slow to respond.
2026-04-20 22:01:38 -04:00
Developer 729583581c FIX: Correct undefined TOTAL_RAM_MB variable in optimize_level_5_everything
In the optimize_level_5_everything() function, two instances of
$TOTAL_RAM_MB (uppercase, undefined) were being passed to functions
instead of $total_ram_mb (lowercase, locally defined from server capacity).

This would cause the functions to receive empty values, leading to
calculation failures or hangs.

Fixed:
- Line 2675: calculate_server_capacity call
- Line 2756: calculate_optimal_php_settings_intelligent call

The variable $total_ram_mb is correctly defined on line 2650 and should
be used throughout the function.
2026-04-20 21:32:47 -04:00
3 changed files with 13 additions and 11 deletions
+5 -5
View File
@@ -1001,11 +1001,11 @@ calculate_server_memory_capacity() {
done <<< "$user_domains"
done <<< "$users"
# Add MySQL memory usage to total
# Add MySQL memory usage to total (with timeout to prevent hanging)
local mysql_memory_mb=0
local mysql_status
local mysql_info
mysql_info=$(detect_mysql_memory_usage 2>/dev/null)
mysql_info=$(timeout 5 detect_mysql_memory_usage 2>/dev/null)
if [ $? -eq 0 ] && [ -n "$mysql_info" ]; then
mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f3 || echo "0")
mysql_status=$(echo "$mysql_info" | cut -d'|' -f4)
@@ -1391,9 +1391,9 @@ detect_mysql_memory_usage() {
local max_connections=150 # Default
if command -v mysql >/dev/null 2>&1; then
# Try to query MySQL directly
buffer_pool_mb=$(mysql -Nse "SELECT ROUND(@@innodb_buffer_pool_size/1024/1024)" 2>/dev/null || echo "0")
max_connections=$(mysql -Nse "SELECT @@max_connections" 2>/dev/null || echo "150")
# Try to query MySQL directly (with 2 second timeout to prevent hanging)
buffer_pool_mb=$(timeout 2 mysql -Nse "SELECT ROUND(@@innodb_buffer_pool_size/1024/1024)" 2>/dev/null || echo "0")
max_connections=$(timeout 2 mysql -Nse "SELECT @@max_connections" 2>/dev/null || echo "150")
fi
# If we couldn't get it from MySQL, try my.cnf
+6 -4
View File
@@ -122,8 +122,9 @@ calculate_max_children_memory_based() {
local mysql_info
mysql_info=$(detect_mysql_memory_usage 2>/dev/null)
if [ $? -eq 0 ]; then
# FIX: detect_mysql_memory_usage returns: memory|status (only 2 fields)
mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f1)
# FIX: detect_mysql_memory_usage returns: buffer_pool|connections|estimated_total_mb|status (4 fields)
# Extract field 3 (estimated_total_mb - the actual memory usage)
mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f3)
fi
# Available memory for PHP-FPM (after system + MySQL reserves)
@@ -372,8 +373,9 @@ calculate_server_capacity() {
local mysql_info
mysql_info=$(detect_mysql_memory_usage 2>/dev/null)
if [ $? -eq 0 ]; then
# FIX: detect_mysql_memory_usage returns: memory|status (only 2 fields)
mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f1)
# FIX: detect_mysql_memory_usage returns: buffer_pool|connections|estimated_total_mb|status (4 fields)
# Extract field 3 (estimated_total_mb - the actual memory usage)
mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f3)
fi
# Available memory for PHP-FPM (after system + MySQL reserves)
+2 -2
View File
@@ -2672,7 +2672,7 @@ optimize_level_5_everything() {
# Calculate server capacity for fair share allocation
local server_capacity_result
server_capacity_result=$(calculate_server_capacity "$TOTAL_RAM_MB")
server_capacity_result=$(calculate_server_capacity "$total_ram_mb")
local server_capacity
server_capacity=$(echo "$server_capacity_result" | cut -d'|' -f1)
local server_memory_per_process
@@ -2753,7 +2753,7 @@ optimize_level_5_everything() {
# Call intelligent three-constraint function
local intel_result
intel_result=$(calculate_optimal_php_settings_intelligent "$username" "$TOTAL_RAM_MB" "$server_capacity" "$traffic_pct" 2>/dev/null || echo "20|dynamic|1|5|ERROR|Failed")
intel_result=$(calculate_optimal_php_settings_intelligent "$username" "$total_ram_mb" "$server_capacity" "$traffic_pct" 2>/dev/null || echo "20|dynamic|1|5|ERROR|Failed")
recommended_max=$(echo "$intel_result" | cut -d'|' -f1)
recommended_memory=$(calculate_optimal_memory_limit "$username" "$domain" "$recommended_max" 2>/dev/null || echo "128M")