Answer the question
In order to leave comments, you need to log in
Sending sms packages: run php script every 5-10 seconds
For the internal service, we decided to attach sending SMS: according to a rough estimate, they will be accumulated and sent in batches of 100-200 pieces in 2-3 hours using http requests to the SMS gateway.
To simplify the scheme, we separate directly queuing messages (mysql database), sending them in the background, and checking statuses.
How can you check every 5-10 seconds for messages with a php script and start a long (up to a couple of minutes) sending process?
Can you please tell me if the above approach is correct?
ps: why often? - Efficiency is needed, and the minute period of cron is too large.
ps: and probably an offtopic question, how do SMS gateways work - they can’t immediately send each request received to the operator using the smpp protocol, or am I mistaken?
Answer the question
In order to leave comments, you need to log in
Daemon?
Simple while(true) { check if there are messages in the queue, if there are - exec the mailing script; sleep(10)}
Don't forget to just unbind stdin and stdout, otherwise exec will wait for the end of the script.
Well, in the cron, you can stick a check on whether the daemon is running and run it if not.
I would use Gearman here. This is a server for organizing and distributing tasks, or, more simply, a message queue server.
You can read about it, for example , here
It will work like this:
A script that initiates sending SMS:
# Подключаемся к серверу
$client= new GearmanClient();
# Регистрируем задачу для фонового выполнения
# "sendsms" - это тип задачи
# $sms - это данные письма
$result = $client->doBackground("sendmail", serialize($sms));
> Tell me, is the above approach correct in principle?
I would implement differently. Redis pubsub for the queue + Node.js (you probably prefer phpDaemon) + database if you need to log. supervisord to monitor the service.
You can code like this, for example (every 15 seconds):
*/1 * * * * root /home/mybin/script.sh; /bin/sleep15; /home/mybin/script.sh /bin/sleep15; /home/mybin/script.sh /bin/sleep15; /home/mybin/script.sh
Or do
exec('myscritp');
sleep(10);
exec('myscript');
ps: and probably an offtopic question, how do SMS gateways work - they can’t immediately send each request received to the operator using the smpp protocol, or am I mistaken?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question