From: Marcus Boerger Date: Sat, 6 Apr 2002 18:49:59 +0000 (+0000) Subject: new feature ignoring repeated error messages (defaults to old behaviour) X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~837 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddc6437e324c31d505610056f01ed3d0c04fdf2c;p=php new feature ignoring repeated error messages (defaults to old behaviour) @You can now disable logging of repeated error messages with two new ini settings ignore_repeated_errors, ignore_repeated_source. @(Marcus) --- diff --git a/main/main.c b/main/main.c index 1601b2b493..e9717b73ac 100644 --- a/main/main.c +++ b/main/main.c @@ -84,6 +84,16 @@ php_core_globals core_globals; PHPAPI int core_globals_id; #endif +#define ERROR_BUF_LEN 1024 + +typedef struct { + char buf[ERROR_BUF_LEN]; + char filename[ERROR_BUF_LEN]; + uint lineno; +} last_error_type; + +static last_error_type last_error; + static void php_build_argv(char *s, zval *track_vars_array TSRMLS_DC); @@ -225,6 +235,8 @@ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateBool, implicit_flush, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals) + STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals) + STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("magic_quotes_gpc", "1", PHP_INI_ALL, OnUpdateBool, magic_quotes_gpc, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("magic_quotes_runtime", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_runtime, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_sybase, php_core_globals, core_globals) @@ -408,8 +420,8 @@ PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC) extended error handling function */ static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) { - char buffer[1024]; - int buffer_len; + char buffer[ERROR_BUF_LEN]; + int buffer_len, display; TSRMLS_FETCH(); buffer_len = vsnprintf(buffer, sizeof(buffer)-1, format, args); @@ -417,9 +429,24 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ if(buffer_len > sizeof(buffer) - 1 || buffer_len < 0) { buffer_len = sizeof(buffer) - 1; } + if (PG(ignore_repeated_errors)) { + if (strncmp(last_error.buf, buffer, sizeof(last_error.buf)) + || (!PG(ignore_repeated_source) + && ((last_error.lineno != error_lineno) + || strncmp(last_error.filename, error_filename, sizeof(last_error.filename))))) { + display = 1; + } else { + display = 0; + } + } else { + display = 1; + } + strlcpy(last_error.buf, buffer, sizeof(last_error.buf)); + strlcpy(last_error.filename, error_filename, sizeof(last_error.filename)); + last_error.lineno = error_lineno; /* display/log the error if necessary */ - if ((EG(error_reporting) & type || (type & E_CORE)) + if (display && (EG(error_reporting) & type || (type & E_CORE)) && (PG(log_errors) || PG(display_errors) || (!module_initialized))) { char *error_type_str; @@ -449,14 +476,14 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ } if (!module_initialized || PG(log_errors)) { - char log_buffer[1024]; + char log_buffer[ERROR_BUF_LEN]; #ifdef PHP_WIN32 if (type==E_CORE_ERROR || type==E_CORE_WARNING) { MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE); } #endif - snprintf(log_buffer, 1024, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); + snprintf(log_buffer, ERROR_BUF_LEN, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); php_log_err(log_buffer TSRMLS_CC); } if (module_initialized && PG(display_errors) @@ -469,8 +496,8 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ "
\n%s: %s in %s on line %d
\n" : "\n%s: %s in %s on line %d\n"; if (PG(xmlrpc_errors)) { - error_format = do_alloca(1024); - snprintf(error_format, 1023, "faultCode%ldfaultString%%s:%%s in %%s on line %%d", PG(xmlrpc_error_number)); + error_format = do_alloca(ERROR_BUF_LEN); + snprintf(error_format, ERROR_BUF_LEN-1, "faultCode%ldfaultString%%s:%%s in %%s on line %%d", PG(xmlrpc_error_number)); } if (prepend_string) { @@ -526,6 +553,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_ } /* Log if necessary */ + if (!display) return; if (PG(track_errors) && EG(active_symbol_table)) { pval *tmp; diff --git a/main/php_globals.h b/main/php_globals.h index e34f273598..4e756c3627 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -76,6 +76,8 @@ struct _php_core_globals { zend_bool display_errors; zend_bool display_startup_errors; zend_bool log_errors; + zend_bool ignore_repeated_errors; + zend_bool ignore_repeated_source; char *error_log; char *doc_root; diff --git a/php.ini-dist b/php.ini-dist index d3c904a3f1..8ef2ede726 100644 --- a/php.ini-dist +++ b/php.ini-dist @@ -257,6 +257,15 @@ display_startup_errors = Off ; error displaying on production web sites. log_errors = Off +; Do not log repeated messages. Repeated errors must occur in same file on same +; line until ignore_repeated_source is set true. +ignore_repeated_errors = Off + +; Ignore source of message when ignoring repeated messages. When this setting +; is On you will not log errors with repeated messages from different files or +; sourcelines. +ignore_repeated_source = Off + ; Store the last error/warning message in $php_errormsg (boolean). track_errors = Off diff --git a/php.ini-recommended b/php.ini-recommended index ce216b4293..628232f8f6 100644 --- a/php.ini-recommended +++ b/php.ini-recommended @@ -262,6 +262,15 @@ display_startup_errors = Off ; error displaying on production web sites. log_errors = On +; Do not log repeated messages. Repeated errors must occur in same file on same +; line until ignore_repeated_source is set true. +ignore_repeated_errors = Off + +; Ignore source of message when ignoring repeated messages. When this setting +; is On you will not log errors with repeated messages from different files or +; sourcelines. +ignore_repeated_source = Off + ; Store the last error/warning message in $php_errormsg (boolean). track_errors = Off