Northern Flame Posted April 22, 2008 Share Posted April 22, 2008 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/102273-solved-sleep/ Share on other sites More sharing options...
trq Posted April 22, 2008 Share Posted April 22, 2008 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/102273-solved-sleep/#findComment-523671 Share on other sites More sharing options...
Northern Flame Posted April 22, 2008 Author Share Posted April 22, 2008 somewhere I read too that using this when working with sensitive data such as passwords can lower the chances of the values being changed or something like that in a hack attempt, is this true? how would that work? Quote Link to comment https://forums.phpfreaks.com/topic/102273-solved-sleep/#findComment-523675 Share on other sites More sharing options...
trq Posted April 22, 2008 Share Posted April 22, 2008 Sorry, but that doesn't make allot of sense. Quote Link to comment https://forums.phpfreaks.com/topic/102273-solved-sleep/#findComment-523677 Share on other sites More sharing options...
iarp Posted April 22, 2008 Share Posted April 22, 2008 I think he's got this backwards 0.o ... wouldn't slowing it down make it more vulnerable? Quote Link to comment https://forums.phpfreaks.com/topic/102273-solved-sleep/#findComment-523679 Share on other sites More sharing options...
trq Posted April 22, 2008 Share Posted April 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/102273-solved-sleep/#findComment-523682 Share on other sites More sharing options...
Northern Flame Posted April 22, 2008 Author Share Posted April 22, 2008 oh alright thanks Quote Link to comment https://forums.phpfreaks.com/topic/102273-solved-sleep/#findComment-523684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.