From bfe796e65c63c3c582bb6b0a16cfb2bee379b265 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 15 Jun 2026 09:35:49 +0800 Subject: [PATCH] Add standalone Laravel optimize script --- public/optimize.php | 134 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 public/optimize.php diff --git a/public/optimize.php b/public/optimize.php new file mode 100644 index 000000000..c6cc1ce8c --- /dev/null +++ b/public/optimize.php @@ -0,0 +1,134 @@ + ["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";