["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"; } // Determine action $action = isset($_GET['action']) ? $_GET['action'] : 'optimize'; if ($action === 'clear') { echo "Action: Clearing All Caches\n\n"; execute("php artisan optimize:clear 2>&1"); } elseif ($action === 'migrate') { echo "Action: Running Migrations\n\n"; execute("php artisan migrate --force 2>&1"); } elseif ($action === 'all') { echo "Action: Full Optimization & Migration Workflow\n\n"; execute("php artisan optimize:clear 2>&1"); execute("php artisan config:cache 2>&1"); execute("php artisan route:cache 2>&1"); execute("php artisan view:cache 2>&1"); execute("php artisan event:cache 2>&1"); execute("php artisan migrate --force 2>&1"); } else { echo "Action: Standard Cache Optimization\n\n"; execute("php artisan optimize:clear 2>&1"); execute("php artisan config:cache 2>&1"); execute("php artisan route:cache 2>&1"); execute("php artisan view:cache 2>&1"); execute("php artisan event:cache 2>&1"); } echo "Optimization workflow finished.\n";