• <bdo id='1m3lm'></bdo><ul id='1m3lm'></ul>

    <tfoot id='1m3lm'></tfoot>

    <small id='1m3lm'></small><noframes id='1m3lm'>

    1. <i id='1m3lm'><tr id='1m3lm'><dt id='1m3lm'><q id='1m3lm'><span id='1m3lm'><b id='1m3lm'><form id='1m3lm'><ins id='1m3lm'></ins><ul id='1m3lm'></ul><sub id='1m3lm'></sub></form><legend id='1m3lm'></legend><bdo id='1m3lm'><pre id='1m3lm'><center id='1m3lm'></center></pre></bdo></b><th id='1m3lm'></th></span></q></dt></tr></i><div id='1m3lm'><tfoot id='1m3lm'></tfoot><dl id='1m3lm'><fieldset id='1m3lm'></fieldset></dl></div>
      <legend id='1m3lm'><style id='1m3lm'><dir id='1m3lm'><q id='1m3lm'></q></dir></style></legend>

      1. PHP 中的并行处理 - 你是怎么做的?

        时间:2023-07-16
          <tfoot id='QL5IH'></tfoot>

              <small id='QL5IH'></small><noframes id='QL5IH'>

              <i id='QL5IH'><tr id='QL5IH'><dt id='QL5IH'><q id='QL5IH'><span id='QL5IH'><b id='QL5IH'><form id='QL5IH'><ins id='QL5IH'></ins><ul id='QL5IH'></ul><sub id='QL5IH'></sub></form><legend id='QL5IH'></legend><bdo id='QL5IH'><pre id='QL5IH'><center id='QL5IH'></center></pre></bdo></b><th id='QL5IH'></th></span></q></dt></tr></i><div id='QL5IH'><tfoot id='QL5IH'></tfoot><dl id='QL5IH'><fieldset id='QL5IH'></fieldset></dl></div>
                <tbody id='QL5IH'></tbody>

                <legend id='QL5IH'><style id='QL5IH'><dir id='QL5IH'><q id='QL5IH'></q></dir></style></legend>
                  <bdo id='QL5IH'></bdo><ul id='QL5IH'></ul>

                  本文介绍了PHP 中的并行处理 - 你是怎么做的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在尝试在 php 中实现一个作业队列.然后队列将作为批处理作业进行处理,并且应该能够并行处理一些作业.

                  I am currently trying to implement a job queue in php. The queue will then be processed as a batch job and should be able to process some jobs in parallel.

                  我已经做了一些研究并找到了几种实现方法,但我并没有真正了解它们的优缺点.

                  I already did some research and found several ways to implement it, but I am not really aware of their advantages and disadvantages.

                  例如通过 fsockopen 多次调用脚本来执行并行处理,如下所述:
                  PHP 中的简单并行处理

                  E.g. doing the parallel processing by calling a script several times through fsockopen like explained here:
                  Easy parallel processing in PHP

                  我发现的另一种方法是使用 curl_multi 函数.
                  curl_multi_exec PHP 文档

                  Another way I found was using the curl_multi functions.
                  curl_multi_exec PHP docs

                  但我认为这 2 种方法会为在主要在后台运行的队列上创建批处理增加相当多的开销?

                  But I think those 2 ways will add pretty much overhead for creating batch processing on a queue that should mainly run on the background?

                  我还阅读了有关 pcntl_fork 的文章,这似乎也是一种处理问题的方法.但是,如果您真的不知道自己在做什么(就像我现在这样),这看起来会变得非常混乱.

                  I also read about pcntl_fork which also seems to be a way to handle the problem. But that looks like it can get really messy if you don't really know what you are doing (like me at the moment).

                  我还查看了 Gearman,但在那里我还需要根据需要动态生成工作线程,而不仅仅是运行一些然后让 Gearman 作业服务器将其发送到免费工人.特别是因为线程应该在执行完一项作业后干净利落地退出,以免遇到最终的内存泄漏(该问题的代码可能并不完美).
                  Gearman 入门

                  I also had a look at Gearman, but there I would also need to spawn the worker threads dynamically as needed and not just run a few and let the gearman job server then sent it to the free workers. Especially because the threads should be exit cleanly after one job has been executed, to not run into eventual memory leaks (code may not be perfect in that issue).
                  Gearman Getting Started

                  所以我的问题是,你如何处理 PHP 中的并行处理?为什么选择你的方法,不同的方法可能有哪些优点/缺点?

                  So my question is, how do you handle parallel processing in PHP? And why do you choose your method, which advantages/disadvantages may the different methods have?

                  推荐答案

                  我使用 exec().它简单而干净.您基本上需要构建一个线程管理器和线程脚本,这将满足您的需求.

                  i use exec(). Its easy and clean. You basically need to build a thread manager, and thread scripts, that will do what you need.

                  我不喜欢 fsockopen() 因为它会打开一个服务器连接,这会建立起来并可能达到 apache 的连接限制

                  I dont like fsockopen() because it will open a server connection, that will build up and may hit the apache's connection limit

                  出于同样的原因,我不喜欢 curl 函数

                  I dont like curl functions for the same reason

                  我不喜欢 pnctl 因为它需要可用的 pnctl 扩展,而且你必须跟踪父/子关系.

                  I dont like pnctl because it needs the pnctl extension available, and you have to keep track of parent/child relations.

                  从来没有玩过齿轮...

                  never played with gearman...

                  这篇关于PHP 中的并行处理 - 你是怎么做的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:多边形算法中的点有时会给出错误的结果 下一篇:PHP 守护进程/工作环境

                  相关文章

                  <legend id='tsUrX'><style id='tsUrX'><dir id='tsUrX'><q id='tsUrX'></q></dir></style></legend>

                  1. <small id='tsUrX'></small><noframes id='tsUrX'>

                  2. <i id='tsUrX'><tr id='tsUrX'><dt id='tsUrX'><q id='tsUrX'><span id='tsUrX'><b id='tsUrX'><form id='tsUrX'><ins id='tsUrX'></ins><ul id='tsUrX'></ul><sub id='tsUrX'></sub></form><legend id='tsUrX'></legend><bdo id='tsUrX'><pre id='tsUrX'><center id='tsUrX'></center></pre></bdo></b><th id='tsUrX'></th></span></q></dt></tr></i><div id='tsUrX'><tfoot id='tsUrX'></tfoot><dl id='tsUrX'><fieldset id='tsUrX'></fieldset></dl></div>
                      <bdo id='tsUrX'></bdo><ul id='tsUrX'></ul>
                    1. <tfoot id='tsUrX'></tfoot>