There is a function of sending sms notifications to php, it takes about 3 seconds, sometimes you have to send out to several numbers at once, the wait increases proportionally.

It is necessary to somehow bring the execution of this task into the background, so as not to make the user wait. The result of the execution is logged separately, so the process can be thrown and forgotten; no result is needed for output.

The process is a function in php with two passed parameters.

It seems to me that decisions about servers with queues are too redundant, because I do not need queues, schedulers and do not even need to save the result of execution

  • one
    you can make an asynchronous http request to your api, call the shell script without waiting for the result (> / dev / null 2> & 1), you can try flashing the answer to the user and continue working. But the best thing, of course, is to delegate such a task to the queue manager. - vp_arth
  • add the sent data to the database. after saving, the user can safely leave the page. Then, using cron, run a script on a schedule that will take this data and send it to the right place. - teran

1 answer 1

I found for myself 2 solutions:

  1. exec("/usr/local/bin/php /usr/local/www/smssend.php ".$telnum." ".$text."> /dev/null 2>&1"); As suggested in the comments, I put my function into a separate file that takes 2 parameters and throws its execution to the mercy of fate In addition to the command to execute the php file, I pass another 2 parameters separated by a space, which are read in the executable file as

    $ telnum = $ argv [1]; $ text = $ argv [2];

  2. I finally took advantage of them - the server of queues, everything was not as difficult as I thought, I put the gearman, in it doBackground - I send the process with parameters to the queue and the worker is processed in the queue
  • In the first version, the main thing is not to forget escapeshellarg - vp_arth