Answer the question
In order to leave comments, you need to log in
How to queue GET requests in API?
There is a service with PHP calls.
The PHP application sends an Asterisk GET request to the server with a phone number.
The Asterisk server has a handler that accepts GET requests with a phone number, after the request sends the data to Asteriks, a call is made to this number.
We have a limit, no more than 10 simultaneous calls.
How can I limit the number of simultaneous requests to 10, and put the rest in a queue?
I think in the direction of Beanstalkd. The PHP application sends a request with data to the Beanstalkd server, then the Worker, receiving the task, makes a request to Asterisk.
Am I thinking right? If so, how can Beanstalkd limit the number of these connections to 10 concurrent connections, or are they just processed sequentially?
I have never encountered queues, so do not kick strong.
Answer the question
In order to leave comments, you need to log in
An elementary queue, which is easily done with a bunch of php (or any other jap) + mysql (or any other storage).
From the site - write the necessary data to the table: phone number, call made or not, handler label, id (with auto-increment).
In the background, run the required number of handlers (at least a hundred), each handler once every few seconds works according to this principle: update queue set worker_id = $id_of_worker where worker_id = null order by id limit 1, and then select * from queue where worker_id = $id_of_worker.
After we received and called back, we write everything to the log and do delete from queue where worker_id = $id_of_worker.
It is done in half an hour, a queue of millions of requests is sorted out in a matter of minutes.
I propose such an algorithm.
You count the number of active calls to Asterisk (it's easy to do, it's not difficult to find an example with Google).
Suppose, 15 calls arrive in the queue. Your worker starts grabbing calls from the queue and feeding the asterisk until it receives a response from it: "enough, there are already 10 active calls in progress." The worker tries to push calls with some frequency until the asterisk can accept them
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question