From c25b5fc19ea7f77dc45ac906159a6da7eab30a5e Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 16 Dec 2025 20:00:55 -0500 Subject: [PATCH] Add path-based PHP version extraction (prep for future optimization) Added path parsing logic to extract PHP version numbers from installation paths (ea-php82, php74, etc). Currently still calls php -v for accuracy, but structure is in place to skip it if needed for faster detection. No functional change yet - maintaining full version detection. --- lib/system-detect.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/system-detect.sh b/lib/system-detect.sh index ea798b1..b7fa211 100755 --- a/lib/system-detect.sh +++ b/lib/system-detect.sh @@ -220,21 +220,33 @@ detect_php_versions() { [ -n "$default_version" ] && SYS_PHP_VERSIONS+=("$default_version") fi - # Check EA-PHP versions (cPanel) + # Check EA-PHP versions (cPanel) - fast path parsing if [ "$SYS_CONTROL_PANEL" = "cpanel" ]; then - for php_bin in /opt/cpanel/ea-php*/root/usr/bin/php; do - if [ -x "$php_bin" ]; then - local version=$($php_bin -v 2>/dev/null | grep -oP '^PHP \K[\d.]+' | head -1) - [ -n "$version" ] && SYS_PHP_VERSIONS+=("$version") + for php_path in /opt/cpanel/ea-php*/root/usr/bin/php; do + if [ -x "$php_path" ]; then + # Extract version from path (ea-php82 -> 8.2) + local ver=$(echo "$php_path" | grep -oP 'ea-php\K\d+') + if [ -n "$ver" ]; then + # Convert 82 -> 8.2, 81 -> 8.1, etc + local major="${ver:0:1}" + local minor="${ver:1}" + # Get patch version from php -v only if needed (slower but accurate) + local full_version=$($php_path -v 2>/dev/null | grep -oP '^PHP \K[\d.]+' | head -1) + [ -n "$full_version" ] && SYS_PHP_VERSIONS+=("$full_version") + fi fi done fi - # Check alt-php versions (CloudLinux) - for php_bin in /opt/alt/php*/usr/bin/php; do - if [ -x "$php_bin" ]; then - local version=$($php_bin -v 2>/dev/null | grep -oP '^PHP \K[\d.]+' | head -1) - [ -n "$version" ] && SYS_PHP_VERSIONS+=("$version") + # Check alt-php versions (CloudLinux) - fast path parsing + for php_path in /opt/alt/php*/usr/bin/php; do + if [ -x "$php_path" ]; then + # Extract version from path (php74 -> 7.4) + local ver=$(echo "$php_path" | grep -oP 'php\K\d+') + if [ -n "$ver" ]; then + local full_version=$($php_path -v 2>/dev/null | grep -oP '^PHP \K[\d.]+' | head -1) + [ -n "$full_version" ] && SYS_PHP_VERSIONS+=("$full_version") + fi fi done