From cef3e3a15064ce45079befa22ebf9aa1386ea000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 26 Feb 2026 13:46:31 +0100 Subject: [PATCH 1/5] fix(windows): ensure DLLs can always be located by PHP --- frankenphp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frankenphp.c b/frankenphp.c index a2e2f6481..1ed4684b3 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -1080,6 +1080,26 @@ static void *php_main(void *arg) { sapi_startup(&frankenphp_sapi_module); + /* TODO: adapted from https://github.com/php/php-src/pull/16958, remove when merged. */ +#ifdef PHP_WIN32 + { + const DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT; + HMODULE module; + wchar_t filename[MAX_PATH]; + if (GetModuleHandleExW(flags, (LPCWSTR)&frankenphp_sapi_module, &module)) { + DWORD len = GetModuleFileNameW(module, filename, MAX_PATH); + if (len > 0 && len < MAX_PATH) { + wchar_t *slash = wcsrchr(filename, L'\\'); + if (slash) { + *slash = L'\0'; + SetDllDirectoryW(filename); + } + } + } + } +#endif + #ifdef ZEND_MAX_EXECUTION_TIMERS /* overwrite php.ini with custom user settings */ char *php_ini_overrides = go_get_custom_php_ini(false); From 7ac4cab2b00971d3e883489f96d6077dbf2f4891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 28 Feb 2026 14:09:49 +0100 Subject: [PATCH 2/5] clang-format --- frankenphp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frankenphp.c b/frankenphp.c index 1ed4684b3..eb5e8d426 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -1080,7 +1080,8 @@ static void *php_main(void *arg) { sapi_startup(&frankenphp_sapi_module); - /* TODO: adapted from https://github.com/php/php-src/pull/16958, remove when merged. */ + /* TODO: adapted from https://github.com/php/php-src/pull/16958, remove when + * merged. */ #ifdef PHP_WIN32 { const DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | From df4a1df7d42f939e6bb394fbbd06f0613576ae6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 1 Mar 2026 14:05:43 +0100 Subject: [PATCH 3/5] fix(windows): handle long paths and SetDllDirectoryW errors Use a 32K buffer instead of MAX_PATH to support long module paths, and check SetDllDirectoryW return value, logging on failure. Co-Authored-By: Claude Opus 4.6 --- frankenphp.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frankenphp.c b/frankenphp.c index eb5e8d426..8bdad47e3 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -1087,14 +1087,21 @@ static void *php_main(void *arg) { const DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT; HMODULE module; - wchar_t filename[MAX_PATH]; + /* Use a larger buffer to support long module paths on Windows. */ + wchar_t filename[32768]; if (GetModuleHandleExW(flags, (LPCWSTR)&frankenphp_sapi_module, &module)) { - DWORD len = GetModuleFileNameW(module, filename, MAX_PATH); - if (len > 0 && len < MAX_PATH) { + const DWORD filename_capacity = + (DWORD)(sizeof(filename) / sizeof(filename[0])); + DWORD len = GetModuleFileNameW(module, filename, filename_capacity); + if (len > 0 && len < filename_capacity) { wchar_t *slash = wcsrchr(filename, L'\\'); if (slash) { *slash = L'\0'; - SetDllDirectoryW(filename); + if (!SetDllDirectoryW(filename)) { + fprintf(stderr, + "Warning: SetDllDirectoryW failed (error %lu)\n", + GetLastError()); + } } } } From 8bd01b83e126bf3b50f89e2d6468df20d54454d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 1 Mar 2026 23:23:21 +0100 Subject: [PATCH 4/5] simplify --- frankenphp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frankenphp.c b/frankenphp.c index 8bdad47e3..e7a3ceb03 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -1090,8 +1090,7 @@ static void *php_main(void *arg) { /* Use a larger buffer to support long module paths on Windows. */ wchar_t filename[32768]; if (GetModuleHandleExW(flags, (LPCWSTR)&frankenphp_sapi_module, &module)) { - const DWORD filename_capacity = - (DWORD)(sizeof(filename) / sizeof(filename[0])); + const DWORD filename_capacity = (DWORD)_countof(filename); DWORD len = GetModuleFileNameW(module, filename, filename_capacity); if (len > 0 && len < filename_capacity) { wchar_t *slash = wcsrchr(filename, L'\\'); From 0d99b4cbc4266689ce044011686f5bfbd7df551e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 2 Mar 2026 11:13:42 +0100 Subject: [PATCH 5/5] clang-format --- frankenphp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frankenphp.c b/frankenphp.c index e7a3ceb03..0bf052cdf 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -1097,8 +1097,7 @@ static void *php_main(void *arg) { if (slash) { *slash = L'\0'; if (!SetDllDirectoryW(filename)) { - fprintf(stderr, - "Warning: SetDllDirectoryW failed (error %lu)\n", + fprintf(stderr, "Warning: SetDllDirectoryW failed (error %lu)\n", GetLastError()); } }