美文网首页
PHP sleep()函数, usleep()函数

PHP sleep()函数, usleep()函数

作者: Mracale | 来源:发表于2021-04-21 10:09 被阅读0次

    PHP sleep() 函数

    定义和用法

    sleep() 函数延迟代码执行若干秒。
    语法sleep(seconds)

    seconds 必需。以秒计的暂停时间。
    返回值

    若成功,返回 0,否则返回 false。
    错误/异常

    如果指定的描述 seconds 是负数,该函数将生成一个 E_WARNING。

    例子

    <?php
    echo date('h:i:s') . "<br />"; //暂停 10 秒
    sleep(10);//重新开始
    echo date('h:i:s');
    ?>
    输出:

    12:00:08 12:00:18

    PHP usleep() 函数

    定义和用法

    usleep() 函数延迟代码执行若干微秒
    语法usleep(microseconds)

    microseconds 必需。以微秒计的暂停时间。
    返回值

    无返回值。
    提示和注释

    注释:在 PHP 5 之前,该函数无法工作于 Windows 系统上。

    注释:一微秒等于百万分之一秒。
    例子

    <?php
    echo date('h:i:s') . "<br />";
    //延迟 10 描述
    usleep(10000000);
    //再次开始
    echo date('h:i:s');
    ?>
    输出:
    09:23:14 09:23:24

    PHP中sleep和unsleep的用法

    当你需要程序暂停执行几秒可以用 sleep

    int sleep ( int seconds ) 程序暂停seconds秒后执行。

    Returns zero on success, or FALSE on error.成功返回0,错误返回false。

    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.

    相关文章

      网友评论

          本文标题:PHP sleep()函数, usleep()函数

          本文链接:https://www.haomeiwen.com/subject/feualltx.html