Skip to content

Commit 364d0ce

Browse files
committed
Don't involve PHP in Apache mpm_winnt control process
Apache mpm_winnt uses a single control process which launches a single child process which in turn creates threads to handle requests. Since the child process is not forked, but rather spawned, and the control process is never involved in request handling, there is no need to power up PHP for the control process. Besides not doing this saves some resources, we no longer have to deal with potential re-attaching to OPcache shared memory which avoids issues due to ASLR, and paves the way to further improvements (such as preloading support for Apache mpm_winnt).
1 parent 3b23de3 commit 364d0ce

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

sapi/apache2handler/sapi_apache2.c

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,30 @@ static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
461461
return OK;
462462
}
463463

464+
static int php_apache_startup_php()
465+
{
466+
#ifdef ZTS
467+
int expected_threads;
468+
if (ap_mpm_query(AP_MPMQ_MAX_THREADS, &expected_threads) != APR_SUCCESS) {
469+
expected_threads = 1;
470+
}
471+
472+
php_tsrm_startup_ex(expected_threads);
473+
# ifdef PHP_WIN32
474+
ZEND_TSRMLS_CACHE_UPDATE();
475+
# endif
476+
#endif
477+
478+
zend_signal_startup();
479+
480+
sapi_startup(&apache2_sapi_module);
481+
if (apache2_sapi_module.startup(&apache2_sapi_module) != SUCCESS) {
482+
return DONE;
483+
}
484+
485+
return OK;
486+
}
487+
464488
static int
465489
php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
466490
{
@@ -484,26 +508,13 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
484508
if (apache2_php_ini_path_override) {
485509
apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
486510
}
487-
#ifdef ZTS
488-
int expected_threads;
489-
if (ap_mpm_query(AP_MPMQ_MAX_THREADS, &expected_threads) != APR_SUCCESS) {
490-
expected_threads = 1;
491-
}
492-
493-
php_tsrm_startup_ex(expected_threads);
494-
# ifdef PHP_WIN32
495-
ZEND_TSRMLS_CACHE_UPDATE();
496-
# endif
497-
#endif
498-
499-
zend_signal_startup();
500-
501-
sapi_startup(&apache2_sapi_module);
502-
if (apache2_sapi_module.startup(&apache2_sapi_module) != SUCCESS) {
511+
#ifndef PHP_WIN32
512+
if (php_apache_startup_php() != OK) {
503513
return DONE;
504514
}
505515
apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
506516
php_apache_add_version(pconf);
517+
#endif
507518

508519
return OK;
509520
}
@@ -750,7 +761,13 @@ zend_first_try {
750761

751762
static void php_apache_child_init(apr_pool_t *pchild, server_rec *s)
752763
{
764+
#ifndef PHP_WIN32
753765
apr_pool_cleanup_register(pchild, NULL, php_apache_child_shutdown, apr_pool_cleanup_null);
766+
#else
767+
php_apache_startup_php();
768+
php_apache_add_version(pchild);
769+
apr_pool_cleanup_register(pchild, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
770+
#endif
754771
}
755772

756773
#ifdef ZEND_SIGNALS

0 commit comments

Comments
 (0)