How can I set the tick_func for all function
function tick_func(){ //for all func,
sleep(1);
}
//sample function
call_any_func(); // this will wait 1 sec.
call_another_func(); // this will wait 1 sec.
How can I set the tick_func for all function
function tick_func(){ //for all func,
sleep(1);
}
//sample function
call_any_func(); // this will wait 1 sec.
call_another_func(); // this will wait 1 sec.
Given your new post in addition to this post, I think I get what you want to do: run a function before or after every other function in the entire script.
PHP does not offer this functionality. You must manually type this function call at the start or end of any function you wish to affect.
<?php
function some_func_sleep() {
sleep(1);
}
function call_any_func() {
some_func_sleep();
// whatever you actually want it to do
}
function call_another_func() {
some_func_sleep();
// whatever other thing you want it to do
}
call_any_func();
call_another_func();
Ta da. It's not exactly beautiful, but it's clear.
Based on the information you've provided, all I can think to point you to is register_tick_function() as possibly what you're trying to do:
declare(ticks=1);
// using a function as the callback
register_tick_function('all_func_sleep', true);
// your code here...
unregister_tick_function('all_func_sleep');
As Matchu says below, this will call after every statement, instead of on function calls, but if you minimize the amount of code between the register... and unregister_tick_function() calls, you can approximate this functionality.