php editor Yuzai will introduce you in detail how to use the sleep function correctly. The sleep function is a function in PHP used to pause script execution for a period of time. The syntax is simple, just pass in the number of seconds you want to pause. By rationally using the sleep function, you can control the time interval between script execution and avoid too fast or too slow execution speed. When writing PHP scripts, proper use of the sleep function can improve the stability and efficiency of the program. Below we will introduce the usage and precautions of the sleep function in detail so that you can easily master it.
Usage: void Sleep(DWORD dwMilliseconds);
Use header file in VC
#include
(Sleep function stores the header file: WinBase.h)
In the gcc compiler, the header files used vary depending on the gcc version
#include
The unit of Sleep() is milliseconds, and the unit of sleep() is seconds (if you need more precision, you can use usleep, the unit is microseconds)
Return value: If process/thread If it is suspended until the time specified by the parameter, 0 will be returned. If there is a signal interruption, the remaining seconds will be returned.
Note:
In VC, the first English character in Sleep is capital "S"
In standard C, it is sleep, do not capitalize it..Use below To illustrate, the specific use depends on which compiler you use. Simply put, VC uses Sleep, and everything else uses sleep.
The general form of the Sleep function:
Sleep(unsigned long);
Among them, the unit in Sleep() is in milliseconds, so if you want the function to stay for 1 second, it should be Sleep(1000);
Under Linux , the "s" in sleep is not capitalized
The unit of sleep() is seconds, and the unit in usleep() is microseconds. In the kernel, sleep is implemented by two functions: pause function and alarm function.
Specially note that the sleep function cannot be used in the Codeblocks environment, because Codeblocks on Windows uses mingw (Gnu's compiler in the Window environment, which can fully use Windows Api) as the compiler, and in stdlib.h The description of sleep is as follows: _CRTIMP void __cdecl __MINGW_NOTHROW _sleep (unsigned long) __MINGW_ATTRIB_DEPRECATED; It can be considered that mingw has abandoned the sleep function, and it is recommended to use Sleep to implement sleep.
Program example:
#include
include
int main()
{
int a;
a=1000;
printf("you");
Sleep(a);/* VC Use Sleep*/
printf("Good"); /*There will be a thousand milliseconds interval between the output "you" and "Good", that is, one second, the unit of sleep() is milliseconds*/
return 0,
}
The above is the detailed content of How to use sleep function?. For more information, please follow other related articles on the PHP Chinese website!