PHP defines PHP code run time

Source: Internet
Author: User
Tags diff sleep usleep

PHP defines PHP code run time
Definitions and usage
The Time_sleep_until () function delays code execution until the specified time.

Grammar
Time_sleep_until (timestamp)

Parameter description
Timestamp required. Time stamp when the script wakes up.

Description
Causes the script to suspend execution until the specified timestamp.

return value
Returns TRUE if successful, and returns FALSE if it fails.

Error/exception
If the specified timestamp is in the past, the function generates a e_warning.

Tips and comments
Note: All signals will be delivered after the script wakes up.

Note: This function is not implemented under the Windows platform.

Time_sleep_until
(PHP 5 >= 5.1.0)

Time_sleep_until-make the script sleep until the specified time
To set the time for a script to delay execution

<?php
if (!function_exists (' Time_sleep_until ')) {
    function time_sleep_until ($future {
        if ($future < time ()) {
             Trigger_error ("Time in Past", e_user_warning);
            return false;
       }
        Sleep ($future-time ());
        return true;
   }
}

<?php
Implementation for < 5.1 or Windows users
if (!function_exists (' Time_sleep_until ')) {
function Time_sleep_until ($future) {
if ($future < time ()) {
Trigger_error ("Time in Past", e_user_warning);
return false;
}
Usleep (($future-microtime (1)) *1000000);
return true;
}
}
?>

<?php
Returns false and generates a warning
Var_dump (Time_sleep_until (Time ()-1));
may only work on faster computers, 'll sleep up to 0.2 seconds
Var_dump (Time_sleep_until (Time () +0.2));
?>

<?php
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 the PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | That's bundled with this package in the file LICENSE, and is |
// | Available at through the World-wide-web at | |
// |                                  Http://www.php.net/license/3_0.txt. |
// | If you don't receive a copy of the PHP license and are unable to | did
// | Obtain it through the World-wide-web, please send a note to |
// |               License@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors:arpad Ray <arpad@php.net> |
// +----------------------------------------------------------------------+
//
$Id: Time_sleep_until.php,v 1.2 2005/12/07 21:08:57 Aidan Exp $

/**
* Replace Time_sleep_until ()
*
* @category PHP
* @package Php_compat
* @link Http://php.net/time_sleep_until
* @author Arpad Ray <arpad@php.net>
* @version $Revision: 1.2 $
* @since PHP 5.1.0
* @require PHP 4.0.1 (trigger_error)
*/
if (!function_exists (' Time_sleep_until ')) {
function Time_sleep_until ($timestamp)
{
List ($usec, $sec) = Explode (', microtime ());
$now = $sec + $usec;
if ($timestamp <= $now) {
User_error (' Specified timestamp is in the past ', e_user_warning);
return false;
}
$diff = $timestamp-$now;
Usleep ($diff * 1000000);
return true;
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.