After laravel uses queues, how does the front end receive a completion prompt
After laravel uses queues, how does the front end receive a completion prompt
<code>使用队列就意味着是异步执行的,肯定不能直接得到结果 前端请求过来,把请求内容放到队列,请求结束,剩下的是异步处理的</code>
Since I can’t get the result, I can only give the front end some friendly tips
Such as "Your request is being processed, please wait patiently" (don’t get hung up on the sentence)
What you said above is correct. Queues are executed asynchronously, and the results cannot be obtained directly.
If you want to use queues. I still want to request. You can use long connections.
For example, if you initiate an operation and join the queue, a row of data (data of the current queue) will generally be generated at this time, and then there will be a field for status; after joining the queue, there will be a callback identifier (such as jobid
) ; If the queue processing performance is excellent, the front end can directly use ajax to poll whether the status of the job has changed. If it changes, the result will be returned
After the queue is added to the stack, the queue is processed in the background, the relevant logic is processed according to the specified method, and the return value is written into the corresponding job callback value!