["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 = []; exec($cmd, $outputLines); $output = implode("\n", $outputLines); } elseif (function_exists('system')) { ob_start(); system($cmd); $output = ob_get_clean(); } else { echo "Error: No command execution functions (proc_open, shell_exec, exec, system) are enabled on this hosting server.\n"; echo "-----------------------------------------\n"; return; } echo $output ? trim($output) : "(no output)"; echo "\n-----------------------------------------\n"; } // 1. Check current status execute("git status 2>&1"); // 2. Pull latest changes execute("git pull origin main 2>&1"); // 3. Re-optimize Laravel cache and run migrations execute("php artisan optimize:clear 2>&1"); execute("php artisan migrate --force 2>&1"); echo "Deployment workflow finished.\n";