PHP Time_nanosleep () function

PHP

The time_nanosleep() function takes seconds and nanoseconds as parameters and returns TRUE on success or FALSE on error.If the delay is interrupted by a signal, an associative array is returned with the following components:< ol>
  • seconds: Indicates the number of seconds remaining in the delay.
  • nanoseconds: Indicates the number of nanoseconds remaining in the delay.
  • Syntax:
    time_nanosleep (seconds, nanoseconds) 
    Parameters used:
    PHP's time_nanosleep() function takes two parameters.
    • seconds : This is a required parameter that specifies the number of seconds.
    • nanoseconds : This is a required parameter that specifies the number of nanoseconds.
    Returned value:returns TRUE on success or FALSE on failure. If the delay is interrupted by a signal, the associative array is returned with the remaining seconds and nanoseconds.Errors and exceptions :
  • The value of the nanoseconds passed as a parameter, must be less than 1,000,000,000.
  • The seconds passed as a parameter must be non-negative.
  • The programs below illustrate the time_nanosleep() function:Program 1 :
    // time display if (time_nanosleep (2, 500000000) === true) { echo "Execution delayed for two and half a second" ; } else 
    { echo " No delay in Execution " ; }
    ?>
    Output:
    Execution delayed for two and half a second 
    Program 2 :
    // time display echo date ( ' h: i: s' );  
    // delay script execution by 2 seconds and half a second
    time_nanosleep (2, 500000000);  
    // display the time again echo ( "" ); echo date ( 'h: i: s' ); ?>
    Output:
    06:45:15 06:45:18 
    Link: http://php.net/manual/en/function.time-nanosleep.php