Monday, January 11, 2010

Sleep for a random time in PHP

If you want your PHP program to halt/sleep for a random period of time, use the folowing:

sleep ( rand ( int min, int max));

*sleep is in seconds

so:
sleep ( rand ( 2, 4));

will sleep for 2 to 4 seconds.




http://php.net/manual/en/function.sleep.php
http://php.net/manual/en/function.rand.php

No comments: