ID:               47524
 Updated by:       johan...@php.net
 Reported By:      shaunspiller at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: Irrelevant
 PHP Version:      5.2.9
 New Comment:

See http://pecl.php.net/package/intercept


Previous Comments:
------------------------------------------------------------------------

[2009-02-27 21:26:47] shaunspiller at gmail dot com

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 this bug report at http://bugs.php.net/?id=47524&edit=1

Reply via email to