如何在向客户端发送响应后执行耗时的任务 [英] How can I do time consuming task after sending response to client

查看:109
本文介绍了如何在向客户端发送响应后执行耗时的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景是:当用户上传图像时,我们会在服务器上进行图像大小调整,但不是等待完成这项工作,我希望它立即响应用户。如果有一个可用的线程,我会正确地使用线程来完成这个任务,但据我所知,php中没有线程,所以我怎样才能实现这个目标呢?感谢您的想法和建议。

The scenario is: when a user upload a image, we do image resizing on the server, but instead of waiting for this job done, I want it to response to the user immediately. if there is a thread available, I would properly just use thread to do this task, but as far as I know , there is no thread in php, so how can I achieve this goal? Thanks for ideas and suggestions.

推荐答案

分叉进程(丑陋且不可靠)或使用JobQueue,如 Gearman

Either fork the process (ugly and unreliable) or use a JobQueue, like Gearman.

这篇关于如何在向客户端发送响应后执行耗时的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆