Fix 5 critical bugs in PHP optimization scripts

CRITICAL FIXES:

1. php-detector.sh - Fix detect_php_version_for_domain parameter order
   - Changed from detect_php_version_for_domain(domain, username)
   - To: detect_php_version_for_domain(username, domain)
   - Updated all 3 call sites to pass username first
   - Fixes: Cannot detect PHP versions for domains

2. php-analyzer.sh - Fix memory calculation bug (line 599)
   - Changed total_mb from field 2 to field 3
   - Was: total_mb=$(echo "$memory_stats" | cut -d'|' -f2)
   - Now: total_mb=$(echo "$memory_stats" | cut -d'|' -f3)
   - Fixes: analyze_domain_php() showing wrong memory usage

3. php-analyzer.sh - Fix variable name collision
   - Renamed second error_count to memory_error_count
   - Prevents overwriting max_children error count
   - Fixes: Memory error detection not working

4. php-analyzer.sh - Fix calculate_server_memory_capacity
   - Changed from get_fpm_memory_usage(pool_name) [wrong function]
   - To: calculate_memory_per_process(username) [correct]
   - Fixed stderr output to stdout for details
   - Fixed indentation causing logic errors
   - Fixes: Server capacity check returning garbage data

5. php-detector.sh - Fix find_fpm_pool_config search order
   - Changed to search username.conf FIRST (cPanel standard)
   - Was searching domain.conf first (doesn't exist in cPanel)
   - cPanel stores pools as /opt/cpanel/ea-phpXX/root/etc/php-fpm.d/USERNAME.conf
   - Fixes: Cannot find FPM pool configurations

6. php-config-manager.sh - Add missing dependency source
   - Added: source php-detector.sh at top of file
   - Was calling find_fpm_pool_config() with no definition
   - Fixes: All backup/restore functions failing

IMPACT:
Before: PHP optimizer completely non-functional
- Could not detect PHP versions
- Could not find FPM pool configs
- Could not backup/restore configs
- Showed wrong memory calculations
- Server capacity check broken

After: All core functionality now works
- PHP version detection working
- FPM pool discovery working
- Backup/restore functional
- Memory calculations accurate
- Capacity checks return valid data
This commit is contained in:
cschantz
2025-12-11 21:19:26 -05:00
parent ca98bfc134
commit d526dece43
4 changed files with 34 additions and 32 deletions
+12 -11
View File
@@ -60,8 +60,8 @@ detect_installed_php_versions() {
# Get PHP version for a specific domain/user
detect_php_version_for_domain() {
local domain="$1"
local username="$2"
local username="$1"
local domain="$2"
case "$SYS_CONTROL_PANEL" in
cpanel)
@@ -208,27 +208,28 @@ find_fpm_pool_config() {
local pool_config=""
# cPanel EA-PHP pools - try domain first, then username
# cPanel EA-PHP pools - search username FIRST (this is how cPanel works!)
if [ -n "$php_version" ]; then
# Try domain-based config first
# Try username-based config (most common)
pool_config="/opt/cpanel/$php_version/root/etc/php-fpm.d/$username.conf"
[ -f "$pool_config" ] && echo "$pool_config" && return 0
# Try domain-based config (rare, but possible)
if [ -n "$domain" ]; then
pool_config="/opt/cpanel/$php_version/root/etc/php-fpm.d/$domain.conf"
[ -f "$pool_config" ] && echo "$pool_config" && return 0
fi
# Try username-based config
pool_config="/opt/cpanel/$php_version/root/etc/php-fpm.d/$username.conf"
[ -f "$pool_config" ] && echo "$pool_config" && return 0
fi
# Search all EA-PHP versions - try domain first, then username
# Search all EA-PHP versions - try username FIRST, then domain
pool_config=$(find /opt/cpanel/ea-php*/root/etc/php-fpm.d/ -name "$username.conf" 2>/dev/null | head -1)
[ -n "$pool_config" ] && echo "$pool_config" && return 0
if [ -n "$domain" ]; then
pool_config=$(find /opt/cpanel/ea-php*/root/etc/php-fpm.d/ -name "$domain.conf" 2>/dev/null | head -1)
[ -n "$pool_config" ] && echo "$pool_config" && return 0
fi
pool_config=$(find /opt/cpanel/ea-php*/root/etc/php-fpm.d/ -name "$username.conf" 2>/dev/null | head -1)
[ -n "$pool_config" ] && echo "$pool_config" && return 0
# Plesk pools
if [ -n "$domain" ]; then
pool_config="/etc/php-fpm.d/plesk-php*-fpm/$domain.conf"