sleep() function in PHP


The sleep() function delays execution of the current script for short time period.

Syntax

sleep(sec)

Parameters

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

Return

The sleep() function returns zero on success.

Example

 Live Demo

<?php
   echo date('h:i:s') . "<br>";
   // wait for 10 seconds
   sleep(10);
   echo date('h:i:s') . "<br>";
   // wait for 5 seconds
   sleep(5);
   echo date('h:i:s');
?>

Output

The following is the output.

02:54:50
02:54:52
02:54:57

Updated on: 30-Dec-2019

611 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements