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

WBOY
Release: 2023-03-02 07:28:02
Original
1081 people have browsed it

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>
Copy after login

The above code shows a 500 millisecond timeout

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!