Sending packages SMS: run a php script every 5-10 seconds

For internal service decided to attach the sending of SMS: according to a rough estimate, they will be accumulated and sent in batches of 100-200 pieces in a 2-3 hour http requests to the SMS gateway.
To simplify the scheme share directly the formulation of messages in a queue (mysql database), sending them in the background, and verification statuses.
How can I check every 5-10 seconds the php script on the messages and start the lengthy (up to couple of minutes) the upload process?
Tell me, am I right in the above approach?

p.s.: why often? — you need the speed, and minute period cron too big.
p.s.: probably offtopic-question, how does SMS gateways — they can not, they each received a request to immediately send the operator a smpp-Protocol, or am I mistaken?
October 8th 19 at 02:05
5 answers
October 8th 19 at 02:07
A demon?
A simple while(true) {check whether the messages in the queue, if there is a exec'AEM mailing list script; sleep(10)}

Do not forget to detach stdin and stdout, otherwise the exec will have to wait for the end of the script.
Well, crowns can stick a check for the running daemon and start it if not.
Just did not have anything to release, because there is no sense to start a new mailing until the end of the old one.

I would do this:
while (true)
if (estimate())
zapuskaetsya();
else
sleep(10s); - ocie.Grady54 commented on October 8th 19 at 02:10
October 8th 19 at 02:09
I would have used Gearman. This is the server of the organization and distribution of tasks, or simply put the message queue server.

Read about it, for example here

It will work like this:
The script is resorting to sending SMS:

# Connect to the server
$client= new GearmanClient();
# Register a task for background execution
# "sendsms" is the type of task
# $text is the letters
$result = $client->doBackground("sendmail", serialize($sms));

At this stage in turn will be added to your SMS and the script continues running, and as soon as one of the senders (of workarou in terminology Gearman) it will be delivered.

In this case, all the grunt work of storing the SMS in a queue, at priority send will take a third party app
Not too complex solution for a relatively simple task? - ocie.Grady54 commented on October 8th 19 at 02:12
Oh, cool!!! - audie_Berge commented on October 8th 19 at 02:15
October 8th 19 at 02:11
> Tell me, am I right in the above approach?
I would have otherwise realized. Redis pubsub queue + Node.js (you probably closer phpDaemon) + database if you need to log. supervisord for the surveillance service.
October 8th 19 at 02:13
You can naudokite for example (every 15sec):
*/1 * * * * root /home/mybin/script.sh; /bin/sleep 15; /home/mybin/script.sh; /bin/sleep 15; /home/mybin/script.sh; /bin/sleep 15; /home/mybin/script.sh

Or do
exec('myscritp');
sleep(10);
exec('myscritp');
In General, if you will send every 2-3 hours, why do you need to pull the script every 5 sec? - ocie.Grady54 commented on October 8th 19 at 02:16
October 8th 19 at 02:15
p.s.: probably offtopic-question, how does SMS gateways — they can not, they each received a request to immediately send the operator a smpp-Protocol, or am I mistaken?

Why, I don't see any problems in an instant sending via smpp.

About implementation, I do not see what is to use a database at all. Launch a daemon in php that listens to a random port. On this port send the message and put them in a queue inside the php(let's say in an array), as only the number of messages reaches the desired number — send them.
Ideally, you will need libevent that would not pull sockets in a perpetual cycle and pcntl for forks, so as not to cause a background job using exec, and other.

Find more questions by tags PHPSMSCron