Solved

sleep random

Posted on 2010-11-14
4
719 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
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…
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.

738 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