Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sleep random

Posted on 2010-11-14
4
Medium Priority
?
769 Views
Last Modified: 2012-05-10
sleep ($min, $max);

is this method to do a random sleep

if not, how to do random sleep
0
Comment
Question by:rgb192
4 Comments
 
LVL 2

Accepted Solution

by:
cap2501 earned 1000 total points
ID: 34133280
sleep( rand( $min, $max) )

would sleep for a random period of time.
0
 
LVL 12

Expert Comment

by:Avinash Zala
ID: 34133701
Go with  cap2501
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 34135808
If you want a little more control over the random nature of the sleep periods, you might consider something like this:
$sleeptimes = range(4,12,2);

Then you can use this to pick one of the elements:
http://us2.php.net/manual/en/function.array-rand.php

Another advantage of using an array of pre-set values, is that you can overload the array with preferred selections.  So if you wanted to mostly sleep for two seconds, but occasionally sleep for one or three seconds, you might have an array like this:
$sleeptimes = array(2,2,2,2,2,1,3);

In case a second is too long to sleep, there is also this:
http://us2.php.net/manual/en/function.usleep.php

In case you know when you want to wake up, there is this:
http://us2.php.net/manual/en/function.time-sleep-until.php
0
 

Author Closing Comment

by:rgb192
ID: 34148008
thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question