com php-src: Move a part of opcache initialization into post_startup phase (when all extensions already loaded).: Zend/zend.c Zend/zend.h ext/opcach
e/ZendAccelerator.c main/main.c
| From: | Dmitry Stogov | Date: | Wed, 18 Oct 2017 14:18:54 +0000 |
| Subject: | com php-src: Move a part of opcache initialization into post_startup phase (when all extensions already loaded).: Zend/zend.c Zend/zend.h ext/opcach e/ZendAccelerator.c main/main.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99784@lists.php.net to get a copy of this message | ||
Commit: b4903aef16ec215f2095ff0a3615524656401660
Author: Dmitry Stogov <dmitry@zend.com> Wed, 18 Oct 2017 17:18:54 +0300
Parents: 7ff13badda58b966ff8fbcc61add48bb5b14117b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b4903aef16ec215f2095ff0a3615524656401660
Log:
Move a part of opcache initialization into post_startup phase (when all extensions already loaded).
Changed paths:
M Zend/zend.c
M Zend/zend.h
M ext/opcache/ZendAccelerator.c
M main/main.c
Diff:
diff --git a/Zend/zend.c b/Zend/zend.c
index 2621851..f881c6c 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -76,6 +76,7 @@ void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_li
void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
+ZEND_API int (*zend_post_startup_cb)(void) = NULL;
void (*zend_on_timeout)(int seconds);
@@ -868,7 +869,7 @@ void zend_register_standard_ini_entries(void) /* {{{ */
/* Unlink the global (r/o) copies of the class, function and constant tables,
* and use a fresh r/w copy for the startup thread
*/
-void zend_post_startup(void) /* {{{ */
+int zend_post_startup(void) /* {{{ */
{
#ifdef ZTS
zend_encoding **script_encoding_list;
@@ -898,6 +899,17 @@ void zend_post_startup(void) /* {{{ */
global_persistent_list = &EG(persistent_list);
zend_copy_ini_directives();
#endif
+
+ if (zend_post_startup_cb) {
+ int (*cb)(void) = zend_post_startup_cb;
+
+ zend_post_startup_cb = NULL;
+ if (cb() != SUCCESS) {
+ return FAILURE;
+ }
+ }
+
+ return SUCCESS;
}
/* }}} */
diff --git a/Zend/zend.h b/Zend/zend.h
index 8ec3ec2..3cd5036 100644
--- a/Zend/zend.h
+++ b/Zend/zend.h
@@ -222,7 +222,7 @@ BEGIN_EXTERN_C()
int zend_startup(zend_utility_functions *utility_functions, char **extensions);
void zend_shutdown(void);
void zend_register_standard_ini_entries(void);
-void zend_post_startup(void);
+int zend_post_startup(void);
void zend_set_utility_values(zend_utility_values *utility_values);
ZEND_API ZEND_COLD void _zend_bailout(const char *filename, uint32_t lineno);
@@ -270,6 +270,7 @@ extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format
extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
+extern ZEND_API int (*zend_post_startup_cb)(void);
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf,
2, 3);
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ....)
ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index e24262f..400db34 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -117,8 +117,10 @@ static int (*accelerator_orig_zend_stream_open_function)(const char *filename,
z
static zend_string *(*accelerator_orig_zend_resolve_path)(const char *filename, size_t
filename_len);
static zif_handler orig_chdir = NULL;
static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL;
+static int (*orig_post_startup_cb)(void);
static void accel_gen_system_id(void);
+static int accel_post_startup(void);
#ifdef ZEND_WIN32
# define INCREMENT(v) InterlockedIncrement64(&ZCSG(v))
@@ -2138,11 +2140,6 @@ static void accel_activate(void)
return;
}
- if (!ZCG(function_table).nTableSize) {
- zend_hash_init(&ZCG(function_table), zend_hash_num_elements(CG(function_table)), NULL,
ZEND_FUNCTION_DTOR, 1);
- zend_accel_copy_internal_functions();
- }
-
/* PHP-5.4 and above return "double", but we use 1 sec precision */
ZCG(auto_globals_mask) = 0;
ZCG(request_time) = (time_t)sapi_get_request_time();
@@ -2567,9 +2564,6 @@ static void accel_move_code_to_huge_pages(void)
static int accel_startup(zend_extension *extension)
{
- zend_function *func;
- zend_ini_entry *ini_entry;
-
#ifdef ZTS
accel_globals_id = ts_allocate_id(&accel_globals_id, sizeof(zend_accel_globals),
(ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
#else
@@ -2614,6 +2608,29 @@ static int accel_startup(zend_extension *extension)
return SUCCESS ;
}
+ orig_post_startup_cb = zend_post_startup_cb;
+ zend_post_startup_cb = accel_post_startup;
+
+ return SUCCESS;
+}
+
+static int accel_post_startup(void)
+{
+ zend_function *func;
+ zend_ini_entry *ini_entry;
+
+ if (orig_post_startup_cb) {
+ int (*cb)(void) = orig_post_startup_cb;
+
+ orig_post_startup_cb = NULL;
+ if (cb() != SUCCESS) {
+ return FAILURE;
+ }
+ }
+
+ zend_hash_init(&ZCG(function_table), zend_hash_num_elements(CG(function_table)), NULL,
ZEND_FUNCTION_DTOR, 1);
+ zend_accel_copy_internal_functions();
+
/********************************************/
/* End of non-SHM dependent initializations */
/********************************************/
diff --git a/main/main..c b/main/main.c
index dfa3378..aeb1226 100644
--- a/main/main.c
+++ b/main/main.c
@@ -2193,7 +2193,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry
*additional_mod
module->info_func = PHP_MINFO(php_core);
}
- zend_post_startup();
+ if (zend_post_startup() != SUCCESS) {
+ return FAILURE;
+ }
module_initialized = 1;