Is it possible to intercept a function call (user
space or built-in) in the Zend Engine and execute user
space code before/after the function call?
=====
Is it possible to intercept a function call (user
space or built-in) in the Zend Engine and execute user
space code before/after the function call?
Yes, you can do this by way of a Zend extension (not a PHP extension mind
you).
The parts of Zend/zend_extensions.h you'll want to pay attention to are:
typedef void (*fcall_begin_handler_func_t)(zend_op_array *op_array);
typedef void (*fcall_end_handler_func_t)(zend_op_array *op_array);
struct _zend_extension {
...
fcall_begin_handler_func_t fcall_begin_handler;
fcall_end_handler_func_t fcall_end_handler;
...
};
-Sara
Is it possible to intercept a function call (user
space or built-in) in the Zend Engine and execute user
space code before/after the function call?Yes, you can do this by way of a Zend extension (not a PHP extension
mind
you).The parts of Zend/zend_extensions.h you'll want to pay attention to
are:
You can also do this by directly wrapping zend_execute. This is the
preferred method if you're writing a profiler or such.
George
Sara Golemon wrote:
typedef void (*fcall_begin_handler_func_t)(zend_op_array *op_array);
typedef void (*fcall_end_handler_func_t)(zend_op_array *op_array);struct _zend_extension {
...
fcall_begin_handler_func_t fcall_begin_handler;
fcall_end_handler_func_t fcall_end_handler;
...
};
What about patching __call() so that it is always called?
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
typedef void (*fcall_begin_handler_func_t)(zend_op_array *op_array);
typedef void (*fcall_end_handler_func_t)(zend_op_array *op_array);struct _zend_extension {
...
fcall_begin_handler_func_t fcall_begin_handler;
fcall_end_handler_func_t fcall_end_handler;
...
};What about patching __call() so that it is always called?
I hesitate to solve a problem via engine patch if it's at all possible to do
within an extension. I havn't entirely mapped it out, but it certainly
looks like some magic methods could be hooked out using a zend_extension:
function __pre($funcname, &$args) {} and function __post($funcname, &$args,
&$retval) for procedural calls and matching object methods for class calls.
No time to look deeper myself, but curious to see what others come up with.
-Sara