How can I perform a time-consuming task after sending a response to the client

Scenario: when a user uploads an image, we do the image resizing on the server, but instead of waiting for this task to complete, I want it to respond immediately to the user. if there is a stream, I would use the stream correctly to accomplish this task, but as far as I know, there is no stream in php, so how can I achieve this? Thanks for the ideas and suggestions.

+1
source share
3 answers

Either fork the process (ugly and untrustworthy) or use JobQueue, such as Gearman .

+4
source

Use a PHP script to do all this processing and call it a shell using shell_exec. Thus, the script will work separately, and your code will bypass this operation by running it in the shell instead of the main code. See my answer here for a similar task:

PHP API supports multiple calls

+2
source

Viking is not reliable, if for some reason your server crashes, resizing will never happen.

Queue the job and use the cron job to do this. There are many ways to create a job queue, you can write your own database or use an existing solution.

+1
source

Source: https://habr.com/ru/post/1235983/


All Articles