Max setting time php

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.

+4
source share
3 answers

The default execution time for Php is 30 seconds.

, script, script.

set_time_limit(0);
+2

30 Second - PHP, , PHP,

  ini_set('max_execution_time', 300);

300 300 , script, php update php.ini.

0

Switch to xampp\php\php.ini

Find max_execution_timeand change to

max_execution_time=900
0
source

Source: https://habr.com/ru/post/1625773/


All Articles