gpt4 book ai didi

php - 带有 FPM 的 PHP7 上的异步/线程

转载 作者:可可西里 更新时间:2023-11-01 01:15:02 25 4
gpt4 key购买 nike

我发现 pthreads 在 web 环境下不工作。我在 Linux Debian 上使用 PHP7.1 on FPM,我还使用 Symfony 3.2。我只想做,例如:

  1. 用户发出请求并PUT一个文件(1GB)
  2. PHP 服务器接收文件并处理它。
  3. 立即返回true给用户(jsonResponse)而不等待处理上传的文件
  4. 稍后,当处理文件完成(移动、复制、复制任何你想要的)时,只需添加一个事件或从后台进行回调并通知用户。

现在。为此,我创建了 Console Command。我从后台执行 Process('bin/console my:command')->start(); 并进行处理。但这对我来说是用火箭筒杀死一只苍蝇。我必须将许多变量传递给这个可执行命令。

我只想创建另一个线程,然后不等待处理就直接返回给用户。

您可能会说这是重复。并指向 pthreads但是 pthreads 声明它仅适用于 CLI。此外,最新版本的 pthreads 不适用于 symfony。 ( fatal error )。

我被困在这一点上并且怀疑我是应该继续为每个上传的文件创建进程还是移动python -> django

最佳答案

你不需要线程。你想要一个作业队列。看看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.

关于php - 带有 FPM 的 PHP7 上的异步/线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41362868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com