U
U
umbertone2014-11-09 15:00:18
PHP
umbertone, 2014-11-09 15:00:18

How to queue API requests in PHP?

I have a number of php scripts that connect as clients to a REST API of a third party service. All scripts use the same login/password for authentication. The problem is that the API server only accepts one connection at a time. Accordingly, if several scripts try to connect to the API server at the same time, they receive an error.
How can I organize a request queue? I thought about creating a database entry or a lock file when opening a connection to the service and removing it when the connection ends, but this does not solve the issue of request ordering.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Hudinsky, 2014-11-09
@myLizzarD

Why does the database not solve the question of precedence? Recorded in the database scripts in the startup order. Then write a script that checks if there are records for execution in the database, if there are, it takes the record and runs the corresponding script, setting a flag in the database, for example, is_executed, to true. And by cron you can run this script every minute.

S
Sergey, 2014-11-09
Protko @Fesor

https://github.com/chrisboulton/php-resque

S
salex772, 2014-12-03
@salex772

queue manager like gearman

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question