debug: add proc_open fallback to git-pull script

This commit is contained in:
2026-05-26 08:27:23 +08:00
parent 8594cdfe95
commit 589df7bd21

View File

@@ -32,6 +32,7 @@ echo "Disabled Functions: " . (ini_get('disable_functions') ?: '(none)') . "\n";
echo "shell_exec status: " . (function_exists('shell_exec') ? 'Enabled' : 'Disabled') . "\n";
echo "exec status: " . (function_exists('exec') ? 'Enabled' : 'Disabled') . "\n";
echo "system status: " . (function_exists('system') ? 'Enabled' : 'Disabled') . "\n";
echo "proc_open status: " . (function_exists('proc_open') ? 'Enabled' : 'Disabled') . "\n";
echo "-----------------------------------------\n\n";
// Move to the root directory (one level up from public)
@@ -41,12 +42,36 @@ if ($rootPath) {
}
echo "Working Directory: " . getcwd() . "\n\n";
// Helper function to execute and print command output
// Helper function to execute commands with proc_open or standard fallbacks
function execute($cmd) {
echo "$ {$cmd}\n";
$output = '';
if (function_exists('shell_exec')) {
if (function_exists('proc_open')) {
$descriptorspec = [
0 => ["pipe", "r"], // stdin
1 => ["pipe", "w"], // stdout
2 => ["pipe", "w"] // stderr
];
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
proc_close($process);
$output = $stdout . $stderr;
} else {
$output = "Error: Failed to open process using proc_open.";
}
} elseif (function_exists('shell_exec')) {
$output = shell_exec($cmd);
} elseif (function_exists('exec')) {
$outputLines = [];
@@ -57,7 +82,7 @@ function execute($cmd) {
system($cmd);
$output = ob_get_clean();
} else {
echo "Error: No command execution functions (shell_exec, exec, system) are enabled on this hosting server.\n";
echo "Error: No command execution functions (proc_open, shell_exec, exec, system) are enabled on this hosting server.\n";
echo "-----------------------------------------\n";
return;
}