Solved

sleep random

Posted on 2010-11-14
4
702 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 250 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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
regular expression for 10 digit number 7 47
Create new password with id in link 5 25
Passing variables to stored procedure 3 34
Load google maps api into wordpress 5 33
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

937 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now