Skip to content

Commit 17454a6

Browse files
committed
fix(windows): ensure DLLs can always be located by PHP
1 parent 25ed020 commit 17454a6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

frankenphp.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,26 @@ static void *php_main(void *arg) {
10701070

10711071
sapi_startup(&frankenphp_sapi_module);
10721072

1073+
/* TODO: adapted from https://github.com/php/php-src/pull/16958, remove when merged. */
1074+
#ifdef PHP_WIN32
1075+
{
1076+
const DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
1077+
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
1078+
HMODULE module;
1079+
wchar_t filename[MAX_PATH];
1080+
if (GetModuleHandleExW(flags, (LPCWSTR)&frankenphp_sapi_module, &module)) {
1081+
DWORD len = GetModuleFileNameW(module, filename, MAX_PATH);
1082+
if (len > 0 && len < MAX_PATH) {
1083+
wchar_t *slash = wcsrchr(filename, L'\\');
1084+
if (slash) {
1085+
*slash = L'\0';
1086+
SetDllDirectoryW(filename);
1087+
}
1088+
}
1089+
}
1090+
}
1091+
#endif
1092+
10731093
#ifdef ZEND_MAX_EXECUTION_TIMERS
10741094
/* overwrite php.ini with custom user settings */
10751095
char *php_ini_overrides = go_get_custom_php_ini(false);

0 commit comments

Comments
 (0)