From 237c84922ef8a0c315b8934f61a348c94879c401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 3 Dec 2024 17:13:06 +0100 Subject: [PATCH] [FrankenPHP] Add Xdebug support (#179) Use the new [`xdebug_connect_to_client()`](https://xdebug.org/docs/all_functions#xdebug_connect_to_client) function if available to allow debugging with Xdebug in worker mode. --- src/frankenphp-symfony/src/Runner.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/frankenphp-symfony/src/Runner.php b/src/frankenphp-symfony/src/Runner.php index 89bcd49..afb704d 100644 --- a/src/frankenphp-symfony/src/Runner.php +++ b/src/frankenphp-symfony/src/Runner.php @@ -27,10 +27,17 @@ public function run(): int // Prevent worker script termination when a client connection is interrupted ignore_user_abort(true); + $xdebugConnectToClient = function_exists('xdebug_connect_to_client'); + $server = array_filter($_SERVER, static fn (string $key) => !str_starts_with($key, 'HTTP_'), ARRAY_FILTER_USE_KEY); $server['APP_RUNTIME_MODE'] = 'web=1&worker=1'; - $handler = function () use ($server, &$sfRequest, &$sfResponse): void { + $handler = function () use ($server, &$sfRequest, &$sfResponse, $xdebugConnectToClient): void { + // Connect to the Xdebug client if it's available + if ($xdebugConnectToClient) { + xdebug_connect_to_client(); + } + // Merge the environment variables coming from DotEnv with the ones tied to the current request $_SERVER += $server;