在多线程PHP [英] Multithreading in PHP

查看:157
本文介绍了在多线程PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想现在创建一个多线程的PHP应用程序。我看过很多文章,介绍如何创建多线程。所有这些例子都建立在跳水上的不同工人的PHP文件的过程。 Actualy这也正是我试图做的,但有一个问题:)

I am trying to create a multi threaded PHP application right now. I have read lots of paper that explains how to create multi threading. All of those examples are built on diving the processes on different worker PHP files. Actualy that is also what I am trying to do but there is a problem :)

有太多的就业机会甚至鸿沟
  在30秒(于执行时间限制)

There are too many jobs even to divide in 30 seconds (which is the execution time limit)

我们使用的是本地网络上的多服务器环境中完成的处理的进程不会彼此连接或共享相同的存储器。我们只需要解雇他们,并让他们在一个确切的时间工作。每个过程的工作原理为0.5秒,但它有一个可能性为30秒工作

We are using multi server environment on local network to complete the processes as the processes do not linked to each other or shares the same memory. We just need to fire them up and let them work at an exact time. Each of the processes works for 0.5 secs but it has a possibility to work for 30 secs.

大多数例子触发了PHP的并等待结果。但不幸的是在我的情况我不需要指望从线程的结果。我只是需要它来执行命令,并把结果写入自己的数据库。

Most of the examples fires up the PHP's and waits for the results. But unfortunately in my situation I dont need to expect a result from the thread. I just need it to execute the command and write the result to its own database.

我如何能实现火起来的PHPS,等待他们为10000原有的工作流程?

How can I achieve to fire up the phps and wait for them to work for 10000 processes ?

附加信息:
我知道,PHP也没有多线程功能,也不是专为。但是,我们必须创建一个方式来使用它,例如我们可以发送请求的http://服务器1 / dothis。 PHP?作业ID = 5 但非标准的方法,让我们等待结果。如果我们能够设法将请求发送到该服务器,而无需等待结果,这将解决我们的问题,我认为还是我们需要完全不同的方法,如用C ++或QT的过程分频器。

ADDITIONAL INFO: I know that PHP neither have multi threading feature nor is built for. But we have to create a way to use it for instance we can send request to http://server1/dothis.php?jobid=5 but standart methods makes us wait for the result. If we can manage to send request to this server without waiting for result it would solve our problem I think or we will need completely different approach such as a process divider with c++ or qt.

推荐答案

正如已经指出的那样,PHP不支持多线程。然而,正如提到tomaszsobczak,也可以让你创建线程,让他们运行,并通过其他脚本,重新连接到他们检查情况等,所谓的 Gearman的

As has been pointed out, php doesn't support multi threading. However, and as tomaszsobczak mentioned, there is a library which will let you create "threads" and leave them running, and reconnect to them through other scripts to check their status and so on, called "Gearman".

从项目的主页:的Gearman提供了一个通用的应用程序框架,以农场没有工作到更适合做这项工作的其他机器或流程的它可以让你做的工作并行,负载均衡处理,和调用功能的语言之间。它可以在各种应用中使用,从高可用性网站到的数据库复制事件的转运。换言之,它是如何分布处理通信的神经系统。

From the project homepage: "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."

拉​​斯穆斯的博客有一个伟大的写了一下这里:
与使用Gearman 玩,你的情况下,它可能只是解决方案,虽然我已经无法读取任何深入的测试案例...有兴趣,虽然知道的,所以如果你最终使用这个,请报到!

Rasmus' blog has a great write up about it here: playing with gearman and for your case, it might just be the solution, although I've not read any in depth test cases... Would be interested to know though, so if you end up using this, please report back!

这篇关于在多线程PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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