gearman-与php结合(1)

WBOY
Release: 2016-06-23 13:37:09
Original
859 people have browsed it

项目需要一个调度模块,对定时任务、条件触发任务(例如按照流量)进行调度。我的设计是:一个扫描器定期扫描数据库里的未开始任务,将任务逐一发给gearman,gearman分发给workers,worker分布式地判断任务触发条件,如果满足触发条件,封装任务发送给gearman,gearman分发给workers,workers对任务进行执行。

gearman的运行架构:

gearman的client&worker api支持很多语言,我需要php的。php分两种,一种是Gearman Extension,是php扩展,是一个封装了libgearman c库的扩展,以.so扩展模块的方式来让php加载,大概步骤是:需要安装libgearman(这个之前要安装libevent等等),再使用pecl安装php的gearman扩展;另一种是Net_Gearman,这是个纯php的库,可以使用pear之间搞下来,使用的话需要require进来的。

这里我还搞清楚了pecl和pear的区别:
Pear:是PHP的扩展代码包,所有的扩展均以PHP代码的形式出现,功能强大,安装简单,甚至可以改改就用。使用的时候,要在代码中进行Include才能够使用。
Pecl:是PHP的标准扩展,可以补充实际开发中所需的功能,所有的扩展都需要安装,并且在php.ini中配置,重启php。

我在安装Gearman Extension的时候,遇到了n个问题,搞不定,放弃了,改用Net_Gearman。
安装:
pear install Net_Gearman
一般会被解压在这里:
php/lib/php/Net/Gearman

api文档

我找到一个老外写的Net_Gearman教程,感觉还不错,里面还有一些例子。我跑通了一个例子,之后会对每个例子进行学习和测试。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!