From:             shaunspiller at gmail dot com
Operating system: Irrelevant
PHP version:      5.2.9
PHP Bug Type:     Feature/Change Request
Bug description:  register_func_function()

Description:
------------
Hi developers!

I have a little feature suggestion for you...


I've been developing a large proxy server-ish thingy using standalone PHP,
with a basic "kernel" loop that handles deferred procedure calls and
timers, and uses stream_select to handle incoming traffic for the network
connections and dispatch them to their watcher objects. (It's co-operative
multitasking!) The problem is the server is very, very complicated and
difficult to debug. Functions nest very deeply.

So I added a function called func_log, which calls PHP's very useful
debug_backtrace() and uses it to fill a log file with a list of every
single function call everywhere and (a cut-down listing of) their
parameters. The log file soon becomes gigantic, but it's a phenomenally
helpful and wonderful way to debug problems and get an overview of the
code. I can review the entire file to find out exactly what goes wrong, and
it helped locate a tricky couple of objects that were spuriously crashing
PHP by recursively calling each other's Close functions(). (Running out of
stack space is difficult to detect otherwise, since PHP logs no error
before crashing.)

So what's my suggestion?

Well the problem with this type of debugging is the need to manually
insert the call to the debugging/logging function at the start of every
custom function (which I've done). It's an awkward hacky sort of solution,
and the function is still called even when debugging/logging isn't wanted,
so it always hurts performance.

I thought about using declare(ticks) and register_tick_function() instead,
but that can't be tuned to just function calls, so it would have to be
called far too many times.

So wouldn't it be wonderful to have some way to register a function to
fire on every function call?

E.g.,:
bool register_func_function( callback function, [, int flags] )

"flags" would determine whether it should fire for just user functions,
just built-in/extension functions, or both.

Obviously it would have to disable as the callback is entered, and
re-enable once it exits.

Perhaps not the best name for it, but anyway, this would be useful for
anyone and everyone trying to debug complex scripts.

I'm not familiar with PHP's internals, but having a simple boolean to
check if register_func_function is enabled shouldn't hurt performance at
all really, right?


That's my suggestion. Thanks very much for reading. Apologies if this has
already been suggested, but I couldn't find it.




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

Reply via email to