Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16259 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93803 invoked by uid 1010); 16 May 2005 19:33:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 64942 invoked from network); 16 May 2005 19:15:28 -0000 Received: from unknown (HELO 3gupload.com) (127.0.0.1) by localhost with SMTP; 16 May 2005 19:15:28 -0000 X-Host-Fingerprint: 69.93.155.18 brian.3gupload.com Received: from ([69.93.155.18:58265] helo=brian.3gupload.com) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 18/27-36148-051F8824 for ; Mon, 16 May 2005 15:15:28 -0400 Received: from [192.168.1.26] (internal.3gupload.com [68.253.30.206]) by brian.3gupload.com (Postfix) with ESMTP id 525C34F0C8C for ; Mon, 16 May 2005 12:15:23 -0700 (PDT) Message-ID: <4288F183.7010804@3gupload.com> Date: Mon, 16 May 2005 14:16:19 -0500 Organization: 3GUpload.com, Inc. User-Agent: Mozilla Thunderbird 1.0 (X11/20041207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------000304080404000902030400" Subject: Patch for php_error_cb From: bmatheny@3gupload.com (Blake Matheny) --------------000304080404000902030400 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Attached is a small patch that allows for a custom error handler to be used instead of php_log_err. This is useful for custom logging of error types that can't be handled with a user-space error handler (such as E_ERROR, E_PARSE, etc.). In order to use a custom error handler set error_log to so:/path/to/so in the php.ini file, where the shared object has a function called error_handler with the following prototype: int error_handler(int type, const char *error_filename, const unsigned int error_lineno, const char *format, va_list args) error_handler should return a non-zero integer if the error was successfully handled and zero otherwise. We are using this patch to log errors to a MySQL database for our defect tracking system. Regards, Blake -- Blake Matheny 3GUpload.com, Inc. Director of Technology 317-472-4962 (W) 317-201-2840 (C) bmatheny@3gupload.com --------------000304080404000902030400 Content-Type: text/plain; name="main.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="main.c.diff" Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.512.2.63 diff -u -r1.512.2.63 main.c --- main/main.c 16 May 2005 08:55:31 -0000 1.512.2.63 +++ main/main.c 16 May 2005 18:54:31 -0000 @@ -645,6 +645,11 @@ if (!module_initialized || PG(log_errors)) { char *log_buffer; + char *logger; + DL_HANDLE dl_handle; + struct stat statbuf; + int error_handler_retval = 0; + int (*error_handler)(int, const char *, const uint, const char *, va_list); #ifdef PHP_WIN32 if (type==E_CORE_ERROR || type==E_CORE_WARNING) { @@ -652,7 +657,27 @@ } #endif spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); - php_log_err(log_buffer TSRMLS_CC); + if ( (logger = strstr(PG(error_log), "so:")) != NULL ) { + logger = strchr(logger, ':'); + *logger++; + if ( stat(logger, &statbuf) == 0 ) { + dl_handle = DL_LOAD(logger); + if ( dl_handle ) { + error_handler = DL_FETCH_SYMBOL(dl_handle, "error_handler"); + if ( error_handler != NULL ) { + error_handler_retval = (*error_handler)(type, error_filename, error_lineno, format, args); + if ( error_handler_retval ) + DL_UNLOAD(dl_handle); + else + php_log_err(log_buffer TSRMLS_CC); + } else + php_log_err(log_buffer TSRMLS_CC); + } else + php_log_err(log_buffer TSRMLS_CC); + } else + php_log_err(log_buffer TSRMLS_CC); + } else + php_log_err(log_buffer TSRMLS_CC); efree(log_buffer); } if (module_initialized && PG(display_errors) --------------000304080404000902030400--