具有FPM的PHP7上的异步/线程

我发现pthreads在Web环境中不起作用.我在Linux Debian上的FPM上使用PHP7.1,我也使用Symfony 3.2.我想要做的就是,例如:

>用户发出请求并放置文件(1GB)
> PHP Server接收文件并对其进行处理.
>立即向用户(jsonResponse)返回true,而无需等待处理上传的文件
>稍后,在完成文件处理(移动,复制,复制所需的任何内容)后,只需添加一个事件或从后台进行回调并通知用户.

现在.为此,我创建了控制台命令.我执行一个Process(‘bin / console my:command’)-> start();从背景,我做我的处理.但这对我来说是用火箭筒杀死一只苍蝇.我必须将许多变量传递给此可执行命令.

我要做的就是创建另一个线程,然后不等待处理就返回给用户.

您可能会说这是重复的.并指向pthreads.但是pthreads声明它仅用于CLI.同样,最新版本的pthreads不适用于symfony. (致命错误).

我被困在这一点上,并且怀疑我是否应该继续为每个上载的文件创建进程或移至python->詹戈

解决方法:

您不需要线程.您想要一个工作队列.看一下Gearman或类似的东西.

Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages. It can be used in a variety of applications, from high-availability web sites to the transport of database replication events. In other words, it is the nervous system for how distributed processing communicates.

上一篇:【Linux】raid管理工具-mdadm-raid0管理


下一篇:GDB下的Linux线程性能非常快,否则极慢