Home  >  Article  >  Backend Development  >  php-fpm - How to achieve a maximum execution time of less than one second in PHP?

php-fpm - How to achieve a maximum execution time of less than one second in PHP?

WBOY
WBOYOriginal
2016-12-01 00:56:541070browse

Use set_time_limit to control the maximum execution time in seconds

Reply content:

Use set_time_limit to control the maximum execution time in seconds

<code><?php

declare(ticks=1);
$start = microtime(true);
register_tick_function(function () use ($start) {
    (microtime(true) - $start < 0.5) or die("timeout\n");
});


function a() {
    echo "do some work\n";
    usleep(600000);
    echo "do another work\n";
}

a();
</code>

The above code shows a 500 millisecond timeout

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn