1010use Symfony \Component \Console \Command \SignalableCommandInterface ;
1111use Symfony \Component \Process \Process ;
1212
13+ use function app ;
14+ use function base_path ;
15+ use function dirname ;
16+
1317#[AsCommand(name: 'octane:frankenphp ' )]
1418class StartFrankenPhpCommand extends Command implements SignalableCommandInterface
1519{
@@ -85,6 +89,9 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
8589 ? "https:// $ host: $ port "
8690 : "http://: $ port " ;
8791
92+ $ debugEnabled = $ this ->debugModeEnabled ($ frankenphpBinary );
93+ $ workerModeEnabled = $ this ->workerCount () == 0 && app ()->environment ('local ' ) && ! $ debugEnabled ;
94+
8895 $ process = tap (new Process ([
8996 $ frankenphpBinary ,
9097 'run ' ,
@@ -93,12 +100,14 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
93100 'APP_ENV ' => app ()->environment (),
94101 'APP_BASE_PATH ' => base_path (),
95102 'APP_PUBLIC_PATH ' => public_path (),
103+ 'APP_INDEX_FILE ' => $ workerModeEnabled ? 'frankenphp-worker.php ' : 'index.php ' ,
96104 'LARAVEL_OCTANE ' => 1 ,
97105 'MAX_REQUESTS ' => $ this ->option ('max-requests ' ),
98106 'REQUEST_MAX_EXECUTION_TIME ' => $ this ->maxExecutionTime (),
99107 'CADDY_GLOBAL_OPTIONS ' => ($ https && $ this ->option ('http-redirect ' )) ? '' : 'auto_https disable_redirects ' ,
100108 'CADDY_SERVER_ADMIN_PORT ' => $ this ->adminPort (),
101109 'CADDY_SERVER_ADMIN_HOST ' => $ this ->option ('admin-host ' ),
110+ 'CADDY_SERVER_FRANKENPHP_OPTIONS ' => $ workerModeEnabled ? 'import worker ' : '' ,
102111 'CADDY_SERVER_LOG_LEVEL ' => $ this ->option ('log-level ' ) ?: (app ()->environment ('local ' ) ? 'INFO ' : 'WARN ' ),
103112 'CADDY_SERVER_LOGGER ' => 'json ' ,
104113 'CADDY_SERVER_SERVER_NAME ' => $ serverName ,
@@ -143,6 +152,23 @@ protected function ensurePortIsAvailable()
143152 }
144153 }
145154
155+ /**
156+ * Check if XDebug is installed and enabled.
157+ *
158+ * @param string $frankenPhpBinary
159+ * @return bool
160+ */
161+ protected function debugModeEnabled ($ frankenPhpBinary )
162+ {
163+ $ status = tap (new Process ([
164+ $ frankenPhpBinary ,
165+ 'php-cli ' ,
166+ dirname (__DIR__ , 2 ).'/bin/checkXdebugMode.php ' ,
167+ ], base_path ()))->run ();
168+
169+ return $ status > 0 ;
170+ }
171+
146172 /**
147173 * Get the path to the FrankenPHP configuration file.
148174 *
0 commit comments