Skip to content

Commit 9c93bbc

Browse files
committed
wip(frankenphp.c): attempt to attach cli thread to existing TSRM
Such design enforce a call to `frankenphp.Init` prior to `frankenphp.EvalScript` . Probably not the best idea. Inspired by the current workers / threads design.
1 parent 239ad52 commit 9c93bbc

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

frankenphp.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,18 @@ static void *execute_script_cli(void *arg) {
13811381
php_embed_module.pretty_name = "PHP CLI embedded in FrankenPHP";
13821382
php_embed_module.register_server_variables = sapi_cli_register_variables;
13831383

1384-
php_embed_init(cli_argc, cli_argv);
1384+
#ifdef ZTS
1385+
(void)ts_resource(0); // Attache thread to existing TSRM.
1386+
#ifdef PHP_WIN32
1387+
ZEND_TSRMLS_CACHE_UPDATE();
1388+
#endif
1389+
#endif
1390+
1391+
// php_request_startup instead of php_embed_init.
1392+
if (php_request_startup() == FAILURE) {
1393+
ts_free_thread();
1394+
return (void *)(intptr_t)1;
1395+
}
13851396

13861397
cli_register_file_handles();
13871398
zend_first_try {
@@ -1400,7 +1411,11 @@ static void *execute_script_cli(void *arg) {
14001411

14011412
exit_status = (void *)(intptr_t)EG(exit_status);
14021413

1403-
php_embed_shutdown();
1414+
php_request_shutdown(NULL); // Instead of php_embed_shutdown.
1415+
1416+
#ifdef ZTS
1417+
ts_free_thread(); // Cleanly detach.
1418+
#endif
14041419

14051420
return exit_status;
14061421
}

0 commit comments

Comments
 (0)