Jump to content

[SOLVED] Sleep()


Northern Flame

Recommended Posts

I was reading about the sleep() function and if I understood it

correctly, it just makes the script load a certain amount of

seconds slower. My question is, when would this apply to real

life coding? In other words, when would I use the sleep() function

and what exactly would I use it for?

 

thanks for any replies

(i know this sounds like a noob question  ;D)

Link to comment
https://forums.phpfreaks.com/topic/102273-solved-sleep/
Share on other sites

Its probably not of that much use in a web programming environment such as how php is normally used, though I have used in on a few occasions within shell scripts. It does what is says, sleeps for (n) seconds.

 

A simple (be it useless) example would be to ping a server every 5 seconds.

 

#!/usr/bin/php
<?php

  while (true) {
    shell_exec('ping foo.com');
    sleep(5);
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/102273-solved-sleep/#findComment-523671
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.