Answer the question
In order to leave comments, you need to log in
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question