From:             [EMAIL PROTECTED]
Operating system: n/a
PHP version:      5.2.0RC3
PHP Bug Type:     Performance problem
Bug description:  error message allocated even if not used

Description:
------------
in the php_error_cb function the spprintf function is called as well as
other code to allocate an error message even if this error message is
never displayed due to logging levels or output settings.  (ie:
error_reporting = E_ALL | ~E_NOTICE would cause all E_NOTICE messages to
be allocated but not displayed).  This patch will short circuit the
function call in these cases...

Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.640.2.23.2.13
diff -u -r1.640.2.23.2.13 main.c
--- main/main.c 17 Aug 2006 13:43:08 -0000      1.640.2.23.2.13
+++ main/main.c 6 Sep 2006 18:07:35 -0000
@@ -657,6 +657,14 @@
        int buffer_len, display;
        TSRMLS_FETCH();
 
+    /* Only go through this code if we are going to do something worth
while... */
+    if ( PG(error_handling) == EH_NORMAL
+         && ( !(EG(error_reporting) & type) || !( PG(log_errors) ||
PG(display_errors) || (!module_initialized) ) )
+         && !( type & (E_ERROR | E_CORE | E_COMPILE_ERROR | E_USER_ERROR
| E_PARSE | E_RECOVERABLE_ERROR) )
+       ) {
+        return;
+    } 
+
        buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format,
args);
 
        /* check for repeated errors to be ignored */


Reproduce code:
---------------
Set error_reporting to include E_NOTICE, use a test file like:

<?php echo $foo; // Produce E_NOTICE ?>



Expected result:
----------------
gdb trace shows the call into vpprintf...

Breakpoint 1, php_error_cb (type=8, error_filename=0x78def0
"/Users/shire/www/error.php", error_lineno=3, format=0x2443f8 "Undefined
variable: %s", args=0xbfffec58 "??x") at
/Users/shire/data/phpcvs-5.2/main/main.c:661
661         if ( PG(error_handling) == EH_NORMAL
(gdb) n
668             buffer_len = vspprintf(&buffer, PG(log_errors_max_len),
format, args);


Actual result:
--------------
With the patch we skip this step when error_reporting does not include
E_NOTICE...

Breakpoint 1, php_error_cb (type=8, error_filename=0x78def0
"/Users/shire/www/error.php", error_lineno=3, format=0x2443f8 "Undefined
variable: %s", args=0xbfffec58 "??x") at
/Users/shire/data/phpcvs-5.2/main/main.c:661
661         if ( PG(error_handling) == EH_NORMAL
(gdb) n
867     }
(gdb) n
zend_error (type=8, format=0x2443f8 "Undefined variable: %s") at
/Users/shire/data/phpcvs-5.2/Zend/zend.c:942
942             if (!EG(user_error_handler)


-- 
Edit bug report at http://bugs.php.net/?id=38734&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38734&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38734&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38734&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38734&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38734&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38734&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38734&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38734&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38734&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38734&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38734&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38734&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38734&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38734&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38734&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38734&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38734&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38734&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38734&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38734&r=mysqlcfg

Reply via email to