Question

There are some other threads on this topic however I couldn't find how it is programmatically possible to send SMS via PHP on specific times, which means cron jobs or through some other way have to be created on very various times.

Here is an example: For a reminder a SMS should be sent always 1 hour before a gathering. The gathering is however on very different times during the day during the week. Thus the SMS has to be sent e. g. on Monday at about 2pm, on tuesday at about 5pm and on friday at about 1am. The next week can be different again. I have all these dates in my database but I don't know how to create these jobs automatically. I have a framework to send SMS (any-sms.biz) but I am stuck with how to create the schedule preferrably with PHP (daemon?) or otherwise (cron jobs?) automatically. Can someone help me?

Was it helpful?

Solution

I suggest you use a cron job - PHP is well suited to running short processes at high frequencies.

A cron job would be perfect - depending on the number of SMS / granularity you could configure it to run a php script every 5 mins.

One way to edit the cron tab of is:

crontab -e

And insert a link to the script

*/5 * * * *   /path/to/script.php

Is the entry that you are looking for - */5 indicating every 5 mins.

The script would then need to query what SMS are due to be sent - i assume you are storing these in the DB. And then send the SMS.

Your PHP script can be set to be executable

chmod a+x script.php

And you need to set the PHP shell in the first line of your script

#!/usr/bin/php -q

Adjusting the path to where PHP is installed on your system

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top