How to use the usleep function in PHP?

In PHP, the usleep function is used to pause the script execution for a specified number of microseconds.

The syntax for using the usleep function is as follows:

usleep(int $micro_seconds): void

The parameter $micro_seconds specifies the number of microseconds to pause before resuming execution, where 1 second equals 1,000,000 microseconds. The function returns null.

Here is an example of using the usleep function:

echo "开始\n";

// 暂停2秒
usleep(2000000);

echo "结束\n";

The above code will output:

开始
(等待2秒后)
结束

In the example above, the script is paused for 2 seconds using the usleep function.

bannerAds