Reputation: 1305
I use this way to send messages:
$AccountSid = $options['twilio_sid'];
$AuthToken = $options['twilio_auth'];
$client = new Services_Twilio($AccountSid, $AuthToken);
$from = $options['twilio_number'];
foreach ($mesages as $message) {
$client->account->sms_messages->create(
$from,
$message['sms_notification'],
$author_notification
);
}
How do I pause it for a number of seconds?
All messages should be send at once but with a delay of a number of seconds from the moment when the script is running.
Do I have to change for something like this: http://twilio-php.readthedocs.org/en/latest/usage/twiml.html#pause ? If Yes how do I make it work inside my loop?
Upvotes: 3
Views: 1715
Reputation: 1244
Twilio employee here.
There is a much simpler way to do what you want to do, just add a <Pause>
within your loop like this:
foreach ($mesages as $message) {
$client->account->sms_messages->create(
$from,
$message['sms_notification'],
$author_notification
);
//Add your pause here using sleep()
sleep(30);
}
This way you can control the delay / sleep yourself!
Upvotes: 2
Reputation: 601
There is a service called IronWorker that may work for you. (I'm in no way affiliated).
From the website: "IronWorker is a multi-language worker platform that runs tasks in the background, in parallel, and at massive scale."
You would basically host your code snippet to send a message with them and execute it with a call from your script. You can set it to whatever delay you like.
$worker->postScheduleSimple('SendSMS', $smsParams, 10)
The service offers a free tier with decent usage limits.
Upvotes: 1
Reputation: 16539
For a simple delay you would use something like sleep, however, if this is being run inside a web request you would probably want the web request to send a message to a background service that would then handle sending the message at a specific time.
I have not done much like this in PHP but if this is what you are after you may want to check out something like beanstalk
I see that you mentioned you are running this in a wordpress plugin - if running an external service yourself is not an option you may want to look into some of the "cron" wordpress plugins to see if you could hack one in to doing what you need.
Upvotes: 1