Skip to content

Don't involve PHP in Apache mpm_winnt control process #7865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/opcache/shared_alloc_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
void **wanted_mapping_base = default_mapping_base_set;

zend_shared_alloc_lock_win32();
/* Mapping retries: When Apache2 restarts, the parent process startup routine
/* Mapping retries: When the server restarts, the parent process startup routine
can be called before the child process is killed. In this case, the mapping will fail
and we have to sleep some time (until the child releases the mapping object) and retry.*/
do {
Expand Down
49 changes: 33 additions & 16 deletions sapi/apache2handler/sapi_apache2.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,30 @@ static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
return OK;
}

static int php_apache_startup_php()
{
#ifdef ZTS
int expected_threads;
if (ap_mpm_query(AP_MPMQ_MAX_THREADS, &expected_threads) != APR_SUCCESS) {
expected_threads = 1;
}

php_tsrm_startup_ex(expected_threads);
# ifdef PHP_WIN32
ZEND_TSRMLS_CACHE_UPDATE();
# endif
#endif

zend_signal_startup();

sapi_startup(&apache2_sapi_module);
if (apache2_sapi_module.startup(&apache2_sapi_module) != SUCCESS) {
return DONE;
}

return OK;
}

static int
php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
Expand All @@ -484,26 +508,13 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
if (apache2_php_ini_path_override) {
apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
}
#ifdef ZTS
int expected_threads;
if (ap_mpm_query(AP_MPMQ_MAX_THREADS, &expected_threads) != APR_SUCCESS) {
expected_threads = 1;
}

php_tsrm_startup_ex(expected_threads);
# ifdef PHP_WIN32
ZEND_TSRMLS_CACHE_UPDATE();
# endif
#endif

zend_signal_startup();

sapi_startup(&apache2_sapi_module);
if (apache2_sapi_module.startup(&apache2_sapi_module) != SUCCESS) {
#ifndef PHP_WIN32
if (php_apache_startup_php() != OK) {
return DONE;
}
apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
php_apache_add_version(pconf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this accesses PG(expose_php), which is controlled by ini settings. It's too early to call this as ini settings haven't been processed yet. It may be safe to move into php_apache_startup_php() since it's called once per process.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is, that is already moved into php_apache_child_init() for PHP_WIN32, and apparently works (tested with default, and both alternatives in php.ini).

#endif

return OK;
}
Expand Down Expand Up @@ -750,7 +761,13 @@ zend_first_try {

static void php_apache_child_init(apr_pool_t *pchild, server_rec *s)
{
#ifndef PHP_WIN32
apr_pool_cleanup_register(pchild, NULL, php_apache_child_shutdown, apr_pool_cleanup_null);
#else
php_apache_startup_php();
php_apache_add_version(pchild);
apr_pool_cleanup_register(pchild, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
#endif
}

#ifdef ZEND_SIGNALS
Expand Down
Loading