Solved

sleep random

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check mysql insert 12 41
Make check boxes work 8 44
Convert php array to comma seperated list 19 34
how to use jquery variable in mysql query 20 36
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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