php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47524 register_func_function()
Submitted: 2009-02-27 21:26 UTC Modified: 2009-02-28 12:57 UTC
From: shaunspiller at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.9 OS: Irrelevant
Private report: No CVE-ID: None
 [2009-02-27 21:26 UTC] 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.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-28 12:57 UTC] shaunspiller at gmail dot com
Ah, PECL, the great bitbucket in the PHP sky for extensions that folks don't know about, can't be used where compatibility is required, and Windows users have no hope of ever figuring out how to load.

It doesn't seem to do a quarter of what I said either (hooking all functions whether specified or not, internal or user-land), so this certainly isn't "Bogus". Mark it "Wont fix" [sic] or put it back Open.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 17:01:33 2024 UTC