SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Using sleep to add delay or increase execution time

We can create a delay by using sleep command inside our PHP script. This command sleep will delay the output by seconds specified in sleep command. Here is the syntax.
sleep(25);
The above command will create a delay of 25 seconds, the next step of execution will be after the delay of 25 seconds.

Some time while testing our scripts we need to add some delay , here it is useful. Say you want to see maximum script execution time of your server. This setting you can know by increasing the sleep time till the set value of execution time at server.

Let us print the time after a delay of 15 seconds.

Here we will first display the time in hour : minute : second format and then use the php flush command to send the output to browser. Then the sleep command will delay the execution by 15 seconds and then again we will print the server time to see the delay. Here is the code.

<?php
echo date('H:i:s');
sleep(15);
flush();
echo "<br>";
echo date('H:i:s');
?>
Out of the two outpus , second one will return after 15 secs
11:36:19
11:36:34




Further readings
Introduction to PHP: How scripting languages work
PHP beginners guide
echo command & escape character for string outputs
Adding delay to the script execution time by using sleep function
Disabling a part of the code by using comments in PHP
Printing Numbers 1 to 50 to screen
PHP Info: Details on PHP script settings & installation at server end
php_uname: Server OS details
PHP.ini file: PHP server configuration setting file for Edit or update
ini_get: PHP function to get configuration settings from php.ini file
ini_set: PHP function to change the configuration settings of php.ini file
PHP Version : What is the version of PHP running at the server
Installing PHP on windows server and IIS
Installing PHP5 on windows server and IIS
Setting up PHP in Windows Vista OS to run in IIS7 web server
Configuration of IIS7 to run PHP scripts with ISAPI module
Extension directory of PHP to store dll files for windows
Error messages Display off or On by using display_errors function in php.ini file
Using HTML inside PHP script, displaying tags


Join Our Email List
Email:  
For Email Newsletters you can trust
Basics
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer