mirror of
https://github.com/php/php-src.git
synced 2024-11-25 19:05:31 +08:00
- don't set php_errormsg on errors that will cause a zend_bailout().
using zend_hash_update() can make things worse in this situation. - new function php_register_pre_request_shutdown(). this way modules can register callbacks that will be called as soon as execution of the script is done but *before* any cleanup (global symbol_table etc) has taken place.
This commit is contained in:
parent
e078a04fd0
commit
3ff75e5b8b
64
main/main.c
64
main/main.c
@ -439,6 +439,19 @@ PHPAPI void php_error(int type, const char *format,...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case E_ERROR:
|
||||
case E_CORE_ERROR:
|
||||
/*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */
|
||||
case E_COMPILE_ERROR:
|
||||
if (module_initialized) {
|
||||
zend_bailout();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (PG(track_errors)) {
|
||||
pval *tmp;
|
||||
|
||||
@ -455,17 +468,6 @@ PHPAPI void php_error(int type, const char *format,...)
|
||||
|
||||
zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case E_ERROR:
|
||||
case E_CORE_ERROR:
|
||||
/*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */
|
||||
case E_COMPILE_ERROR:
|
||||
if (module_initialized) {
|
||||
zend_bailout();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -652,33 +654,51 @@ static void php_message_handler_for_zend(long message, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
static void php_start_post_request_startup(void *data)
|
||||
static void php_start_request_hook(void *data)
|
||||
{
|
||||
php_post_request_startup *ptr = (php_post_request_startup *) data;
|
||||
php_request_hook *ptr = (php_request_hook *) data;
|
||||
|
||||
ptr->func(ptr->userdata);
|
||||
}
|
||||
|
||||
static void php_execute_post_request_startup(PLS_D)
|
||||
static void php_execute_pre_request_shutdown(PLS_D)
|
||||
{
|
||||
zend_llist_apply(&PG(ll_post_request_startup), php_start_post_request_startup);
|
||||
zend_llist_apply(&PG(ll_pre_request_shutdown), php_start_request_hook);
|
||||
}
|
||||
|
||||
static void php_destroy_post_request_startup(void)
|
||||
static void php_execute_post_request_startup(PLS_D)
|
||||
{
|
||||
zend_llist_apply(&PG(ll_post_request_startup), php_start_request_hook);
|
||||
}
|
||||
|
||||
static void php_destroy_request_hooks(void)
|
||||
{
|
||||
PLS_FETCH();
|
||||
|
||||
zend_llist_destroy(&PG(ll_pre_request_shutdown));
|
||||
zend_llist_destroy(&PG(ll_post_request_startup));
|
||||
}
|
||||
|
||||
static void php_init_post_request_startup(PLS_D)
|
||||
static void php_init_request_hooks(PLS_D)
|
||||
{
|
||||
zend_llist_init(&PG(ll_post_request_startup), sizeof(php_post_request_startup), NULL, 0);
|
||||
zend_llist_init(&PG(ll_post_request_startup), sizeof(php_request_hook), NULL, 0);
|
||||
zend_llist_init(&PG(ll_pre_request_shutdown), sizeof(php_request_hook), NULL, 0);
|
||||
}
|
||||
|
||||
void php_register_pre_request_shutdown(void (*func)(void *), void *userdata)
|
||||
{
|
||||
php_request_hook ptr;
|
||||
PLS_FETCH();
|
||||
|
||||
ptr.func = func;
|
||||
ptr.userdata = userdata;
|
||||
|
||||
zend_llist_add_element(&PG(ll_pre_request_shutdown), &ptr);
|
||||
}
|
||||
|
||||
void php_register_post_request_startup(void (*func)(void *), void *userdata)
|
||||
{
|
||||
php_post_request_startup ptr;
|
||||
php_request_hook ptr;
|
||||
PLS_FETCH();
|
||||
|
||||
ptr.func = func;
|
||||
@ -692,7 +712,7 @@ int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
|
||||
global_lock();
|
||||
|
||||
php_output_startup();
|
||||
php_init_post_request_startup(PLS_C);
|
||||
php_init_request_hooks(PLS_C);
|
||||
|
||||
#if APACHE
|
||||
/*
|
||||
@ -772,7 +792,6 @@ void php_request_shutdown(void *dummy)
|
||||
ELS_FETCH();
|
||||
SLS_FETCH();
|
||||
|
||||
php_destroy_post_request_startup();
|
||||
sapi_send_headers();
|
||||
php_end_ob_buffering(SG(request_info).headers_only?0:1);
|
||||
|
||||
@ -783,11 +802,11 @@ void php_request_shutdown(void *dummy)
|
||||
zend_deactivate(CLS_C ELS_CC);
|
||||
sapi_deactivate(SLS_C);
|
||||
|
||||
php_destroy_request_hooks();
|
||||
php_destroy_request_info(NULL);
|
||||
shutdown_memory_manager(CG(unclean_shutdown), 0);
|
||||
php_unset_timeout();
|
||||
|
||||
|
||||
#if CGI_BINARY
|
||||
fflush(stdout);
|
||||
if(request_info.php_argv0) {
|
||||
@ -1275,6 +1294,7 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_
|
||||
EG(active_op_array) = EG(main_op_array);
|
||||
php_execute_post_request_startup(PLS_C);
|
||||
zend_execute(EG(main_op_array) ELS_CC);
|
||||
php_execute_pre_request_shutdown(PLS_C);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,6 +320,7 @@ int mergesort(void *base, size_t nmemb, register size_t size, int (*cmp) (const
|
||||
extern PHPAPI int _php_error_log(int opt_err,char *message,char *opt,char *headers);
|
||||
|
||||
PHPAPI void php_register_post_request_startup(void (*func)(void *), void *userdata);
|
||||
PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
|
||||
|
||||
PHPAPI int cfg_get_long(char *varname, long *result);
|
||||
PHPAPI int cfg_get_double(char *varname, double *result);
|
||||
|
@ -97,13 +97,14 @@ struct _php_core_globals {
|
||||
unsigned char header_is_being_sent;
|
||||
|
||||
zend_llist ll_post_request_startup;
|
||||
zend_llist ll_pre_request_shutdown;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
void (*func)(void *);
|
||||
void *userdata;
|
||||
} php_post_request_startup;
|
||||
} php_request_hook;
|
||||
|
||||
#endif /* _PHP_GLOBALS_H */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user