I want to create a function that can catch the maximum runtime, I found this function.
function runfunction($func,$args,$msgs){
try {
$t1 = time();
$result = "";
while (true) {
$time_2 = time();
$result = call_user_func_array($func, $args);
if($result){ return $result; }
$time_spent = time() - $t1;
$time_funcs = time() - $time_2;
getThrow($time_spent,$time_funcs,$msgs);
}
} catch(Exception $e) {
echo "<html>\n<head>\n<title>Time Execution</title>\n</head>\n";
echo "<body style='font-family: monospace; cursor: default'>\n";
echo 'Caught exception : ', $e->getMessage(), "\n";
echo "</body>\n</html>";
exit(1);
}
}
function getThrow($param1,$param2,$msgs){
if($param2 >= $this->time_sublimit($param1)) {
throw new Exception($msgs);
}
}
The concept of the function above is to get the length of time for the function to be performed, and then compare it with the actual time.
The problem is that the process is stuck inside this function for more than 30 seconds.
$result = call_user_func_array($func, $args);
I am still getting this error.
Fatal error: Maximum execution time of 30 seconds exceeded
you can catch the maximum execution time when the process is still inside this function.
$result = call_user_func_array($func, $args);
In this case, I use the sqlsrv_connect function.
runfunction("sqlsrv_connect", array($this->host, $connectionInfo), $errormessage);
i Set the maximum runtime within 30 seconds.