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
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
Share on other sites

I think he's got this backwards 0.o ... wouldn't slowing it down make it more vulnerable?

 

No, the fact of the matter is the request has been sent, doesn't matter how fast / slow the server takes to respond, the request remains the same.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.