PHP sleep() function, usleep() function
PHP sleep() function
Definition and usage
sleep() function delays code execution for a few seconds.
Syntax sleep(seconds)
seconds required. Pause time in seconds.
Return value
If successful, return 0, otherwise return false.
Errors/Exceptions
If the specified description seconds is a negative number, this function will generate an E_WARNING.
Example
<?php echo date('h:i:s') . "<br />"; //暂停 10 秒 sleep(10);//重新开始 echo date('h:i:s'); ?>
Output:
12:00:08 12:00:18
PHP usleep() function
Definition and usage
usleep() function delays code execution for a number of microseconds.
Syntax usleep(microseconds)
microseconds required. Pause time in microseconds.
Return value
No return value.
Tips and Notes
Note: Prior to PHP 5, this function did not work on Windows systems.
Note: One microsecond is equal to one millionth of a second.
Example
<?php echo date('h:i:s') . "<br />"; //延迟 10 描述 usleep(10000000); //再次开始 echo date('h:i:s'); ?>
Output:
09:23:14 09:23:24
Usage of sleep and unsleep in PHP
When you need the program to pause execution for a few seconds, you can use sleep
int sleep (int $seconds) program Pause for $seconds seconds before executing.
Returns zero on success, or FALSE on error. Returns zero on success, or false on error.
If the call was interrupted by a signal, sleep() returns a non-zero value. On Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.
If the call is interrupted by a signal, this function returns a non-zero value. On Windows platforms, this value is always 192 (this value is the constant value of WAIT_IO_COMPLETION in the Windows API that waits for IO to complete). The return value on other platforms is the number of seconds sleep has not been executed.
If the specified number of seconds is negative, this function will generate a E_WARNING.
If the parameter is a negative value, the function generates a warning error.
When you need the program to pause execution for 1 second, you can use usleep
void usleep ( int $micro_seconds )
Delays program execution for the given number of micro seconds.
usleep parameter is microseconds and has no return value.
When you need the program execution unit to be smaller (less than microseconds), you can use
time_nanosleep() - Delay for a number of seconds and nanoseconds
If you want the program to pause execution to a certain point in time, you can use
time_sleep_until()- Make the script sleep until the specified time
For more articles related to PHP sleep() function and usleep() function, please pay attention to PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
