Skip to content

Commit 6c9d239

Browse files
committed
Fix crash on OSX by reworking how module startup is done.
This matches how the Apache2 SAPI does startup, and seems to be required to ensure that the module is initialized in each new thread.
1 parent 6a3feb4 commit 6c9d239

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/node_php_embed.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ class node_php_embed::PhpRequestWorker : public AsyncMessageWorker {
112112
};
113113

114114
/* PHP extension metadata */
115+
extern zend_module_entry node_php_embed_module_entry;
116+
117+
static int node_php_embed_startup(sapi_module_struct *sapi_module) {
118+
TRACE(">");
119+
if (php_module_startup(sapi_module, &node_php_embed_module_entry, 1)==FAILURE) {
120+
return FAILURE;
121+
}
122+
TRACE("<");
123+
return SUCCESS;
124+
}
115125

116126
static int node_php_embed_ub_write(const char *str, unsigned int str_length TSRMLS_DC) {
117127
TRACE(">");
@@ -250,7 +260,7 @@ static void node_php_embed_ensure_init(void) {
250260
php_embed_init(argc, argv PTSRMLS_CC);
251261
// shutdown the initially-created request
252262
php_request_shutdown(NULL);
253-
zend_startup_module(&node_php_embed_module_entry);
263+
//zend_startup_module(&node_php_embed_module_entry);
254264
node::AtExit(ModuleShutdown, NULL);
255265
TRACE("<");
256266
}
@@ -261,6 +271,7 @@ NAN_MODULE_INIT(ModuleInit) {
261271
php_embed_module.php_ini_ignore = true;
262272
php_embed_module.php_ini_ignore_cwd = true;
263273
php_embed_module.ini_defaults = NULL;
274+
php_embed_module.startup = node_php_embed_startup;
264275
php_embed_module.ub_write = node_php_embed_ub_write;
265276
php_embed_module.flush = node_php_embed_flush;
266277
php_embed_module.register_server_variables = node_php_embed_register_server_variables;

0 commit comments

Comments
 (0)