-
-
Save asgrim/2ffec166dfc4c1af9b21ae94f7100a8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo { | |
public function x() { | |
sleep(1); | |
} | |
} | |
add_monitoring(); | |
$foo = new Foo(); | |
$foo->x(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZEND_NAMED_FUNCTION(my_custom_handler) | |
{ | |
// Never make it into here... | |
original_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | |
} | |
PHP_FUNCTION(add_monitoring) | |
{ | |
zend_function *original_function; | |
int handler_index; | |
zend_class_entry *ce; | |
// https://www.phpinternalsbook.com/php7/extensions_design/hooks.html#overwriting-an-internal-function | |
ce = zend_hash_str_find_ptr(EG(class_table), "foo", sizeof("foo") - 1); | |
original_function = zend_hash_str_find_ptr(&ce->function_table, "x", sizeof("x")-1); | |
original_handler = original_function->internal_function.handler; | |
original_function->internal_function.handler = my_custom_handler; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment