Solved

sleep random

Posted on 2010-11-14
4
699 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

760 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

20 Experts available now in Live!

Get 1:1 Help Now