PHP Code to generate event to repeat in a random shuffle of intervals between 1-20 seconds
This program sends an email every 20 sec.
开发者_开发问答How can I amend the code to have it send an email, then pause for a random number of seconds between 1 and 20, then repeat till the end ? Any help on this is much appreciate. Thanks in advance!
Here is the code that is associated with the Delay section of the User Interface as it is
if (!$delaySecs) {
$delaySecs = 20;
}
<input name="delaySecs" type="text" value="<? print $delaySecs; ?>" size="10">
As i understand you are executing the mail function in a loop for x number of times.Use sleep(rand(1, 20));
before the execution.
Use the sleep function to pause execution.
If you are looking to pause the same amount of time between the sending of each email:
// $recipients is an array of email addresses
foreach ($recipients as $recipient) {
sendEmail($recipient);
sleep($delaySecs);
}
I'm assuming you already know how to get the recipients and how to send the email. The above code is an example only how to pause between the sending of emails.
精彩评论