diff --git a/bin/checkXdebugMode.php b/bin/checkXdebugMode.php new file mode 100644 index 000000000..1396ddaf0 --- /dev/null +++ b/bin/checkXdebugMode.php @@ -0,0 +1,3 @@ +debugModeEnabled($frankenphpBinary); + $workerModeEnabled = $this->workerCount() == 0 && app()->environment('local') && ! $debugEnabled; + $process = tap(new Process([ $frankenphpBinary, 'run', @@ -93,12 +100,14 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve 'APP_ENV' => app()->environment(), 'APP_BASE_PATH' => base_path(), 'APP_PUBLIC_PATH' => public_path(), + 'APP_INDEX_FILE' => $workerModeEnabled ? 'frankenphp-worker.php' : 'index.php', 'LARAVEL_OCTANE' => 1, 'MAX_REQUESTS' => $this->option('max-requests'), 'REQUEST_MAX_EXECUTION_TIME' => $this->maxExecutionTime(), 'CADDY_GLOBAL_OPTIONS' => ($https && $this->option('http-redirect')) ? '' : 'auto_https disable_redirects', 'CADDY_SERVER_ADMIN_PORT' => $this->adminPort(), 'CADDY_SERVER_ADMIN_HOST' => $this->option('admin-host'), + 'CADDY_SERVER_FRANKENPHP_OPTIONS' => $workerModeEnabled ? 'import worker' : '', 'CADDY_SERVER_LOG_LEVEL' => $this->option('log-level') ?: (app()->environment('local') ? 'INFO' : 'WARN'), 'CADDY_SERVER_LOGGER' => 'json', 'CADDY_SERVER_SERVER_NAME' => $serverName, @@ -141,6 +150,23 @@ protected function ensurePortIsAvailable() } } + /** + * Check if XDebug is installed and enabled. + * + * @param string $frankenPhpBinary + * @return bool + */ + protected function debugModeEnabled($frankenPhpBinary) + { + $status = tap(new Process([ + $frankenPhpBinary, + 'php-cli', + dirname(__DIR__, 2).'/bin/checkXdebugMode.php', + ], base_path()))->run(); + + return $status > 0; + } + /** * Get the path to the FrankenPHP configuration file. * diff --git a/src/Commands/stubs/Caddyfile b/src/Commands/stubs/Caddyfile index 82508830d..12617c040 100644 --- a/src/Commands/stubs/Caddyfile +++ b/src/Commands/stubs/Caddyfile @@ -1,10 +1,14 @@ +(worker) { + worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT} +} + { {$CADDY_GLOBAL_OPTIONS} admin {$CADDY_SERVER_ADMIN_HOST}:{$CADDY_SERVER_ADMIN_PORT} frankenphp { - worker "{$APP_PUBLIC_PATH}/frankenphp-worker.php" {$CADDY_SERVER_WORKER_COUNT} + {$CADDY_SERVER_FRANKENPHP_OPTIONS} } } @@ -31,7 +35,7 @@ {$CADDY_SERVER_EXTRA_DIRECTIVES} php_server { - index frankenphp-worker.php + index {$APP_INDEX_FILE} # Required for the public/storage/ directory... resolve_root_symlink }