Categories
PHP Tips & Tutorials

PHP: Delay Function that Halt Code Execution Temporarily and Then Resume It

Sometimes you need to temporarily halt the code execution of your PHP script for certain seconds and then automatically resume it. For example, some mail delivery servers have the restriction that you have to wait a certain interval such as 12 seconds before sending another email.

You can tell your PHP script to stop for 12 seconds before continuing down with the rest of the code by sleep() function:

sleep(12); // freeze PHP execution for 12 seconds before going ahead

That’s it. When it is executed to this line, PHP will freeze for 12 seconds, doing nothing, and then go on with the line immediately after this line.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.