I need a function that will throw a catchable exception after a callable function has taken to long to complete it's task.
Note: I am not referring to the max execution time for a PHP script.
The function should work like the call_user_func
except that it takes a time limit in seconds for the callable.
function task() {
// does a lot of work...
}
try {
call_user_func('task', 30); // limit to 30 seconds
} catch (TimeoutException $ex) {
// ....
}
I can not add custom logic to the task
function to throw an exception on it's own. The idea is to force the callable methods to abort or fail after X number of seconds.
I have CLI scripts that I want to regulate how long they take to complete a task.