Home  >  Article  >  Daily Programming  >  PHP implements delayed execution program

PHP implements delayed execution program

藏色散人
藏色散人Original
2019-01-17 14:05:3710317browse

PHP delays the execution of the program, we can implement it directly through the sleep function in PHP. The sleep function means delayed execution.

PHP implements delayed execution program

Below we will introduce simple code examples to introduce how to delay the execution of programs in PHP.

The code example is as follows:

<?php

// 当前时间
echo date("Y-m-d H:i:s");

// 延迟5秒钟
sleep(5);

echo date("Y-m-d H:i:s");

The output delay result is as shown in the figure below:

PHP implements delayed execution program

sleep means delay.

sleep ( int $seconds ) : int

The program delays execution for the specified seconds seconds. The parameter seconds indicates the number of seconds to pause.

Return value, 0 is returned on success, FALSE is returned on error.

If the function call is terminated by a signal, sleep() will return a non-zero value. On Windows, the value is always 192 (i.e. the value of the Windows API constant WAIT_IO_COMPLETION). On other platforms, the return value is the number of seconds remaining without sleep.

Error/Exception: If the specified seconds is a negative number, this function will generate an E_WARNING level error.

This article is an introduction to the method of implementing delayed execution of programs in PHP. It is simple and easy to understand. I hope it will be helpful to friends in need!

The above is the detailed content of PHP implements delayed execution program. For more information, please follow other related articles on the PHP Chinese website!

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