time_nanosleep() function in PHP


The time_nanosleep() function delays execution of the current script for few seconds and nanoseconds.

Syntax

time_nanosleep(sec, nsec)

Parameters

  • sec − The number of seconds to delay the script.

  • nsec − The number of nanoseconds to delay the script.

Return

The time_nanosleep() function returns true on success.

Example

 Live Demo

<?php
   echo date('h:i:s') . "<br>";
   // wait for 1.5 seconds
   time_nanosleep(1,500000000);
   echo date('h:i:s') . "<br>";
   // wait for 2.5 seconds
   time_nanosleep(2,500000000);
   echo date('h:i:s');
?>

Output

The following is the output.

02:57:04
02:57:06
02:57:08

Updated on: 30-Dec-2019

34 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements