T
T
Tutucu2020-08-14 12:01:02
Laravel
Tutucu, 2020-08-14 12:01:02

How to give a JSON response in php and then execute a "long" script?

Good afternoon. I am creating a service in PHP and Laravel that uses a third-party API, this very API is called too long (up to 10 seconds), but I have strict requirements to return any JSON response in no more than 3 seconds (this is a very strict condition). Because my service is also an API that only returns JSON to be able to use JS on a neti client.
In these 3 seconds, I need to send a json stub with a response like "Your data is being prepared, please contact again in 10 seconds", and at this time run another PHP script that will visit a third-party API, collect all the necessary data and prepare them for the next normal and target request.
How can I do that?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Bay, 2020-08-14
@Tutucu

queues.
If it’s quite simple, then you do a task for an api request, and cron executes it on the side.

T
ThunderCat, 2020-08-14
@ThunderCat

1) Run the console script in the background. IMHO best choice.
2) Give the header of the end of the connection and do everything you need to do next, also a normal option. More details: link
3) Queues - requires additional gestures, and if you can solve it with the above native means, IMHO it's too hemorrhagic ...

I
IIIIIIIIIIIII, 2020-10-18
@IIIIIIIIIIIIIII

Hello, in 2016 you faced the same problem as me now. Did you happen to solve this question then?) https://qna.habr.com/q/367366 Why does the color change to shades of gray when replacing the color in Photoshop?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question