共计 2174 个字符,预计需要花费 6 分钟才能阅读完成。
原文:
This protocol plugin allows you to map HTTP requests to Gearman jobs. It only provides client job submission currently, but it may be extended to support other request types in the future. The plugin can handle both GET and POST data, the latter being used to send a workload to the job server. The URL being requested is translated into the function being called.
For example, the request:
POST /reverse HTTP/1.1
Content-Length: 12
Hello world!
Is translated into a job submission request for the function“reverse”and workload“Hello world!”. This will respond with:
HTTP/1.0 200 OK
X-Gearman-Job-Handle: H:lap:4
Content-Length: 12
Server: Gearman/0.8
!dlrow olleH
The following headers can be passed to change the behavior of the job:
* X-Gearman-Unique: <unique key>
* X-Gearman-Background: true
* X-Gearman-Priority: <high|low>
For example, to run a low priority background job, the following request can be sent:
POST /reverse HTTP/1.1
Content-Length: 12
X-Gearman-Background: true
X-Gearman-Priority: low
Hello world!
The response for this request will not have any data associated with it since it was a background job:
HTTP/1.0 200 OK
X-Gearman-Job-Handle: H:lap:6
Content-Length: 0
Server: Gearman/0.8
The HTTP protocol should be considered experimental.
应用场景:
开启 gearman http 监听功能,让前端以 web api 方式调用 gearman job
起用方式:
在 gearmand 的起动参数中加上:
/usr/local/gearman/sbin/gearmand \
-l /usr/local/gearman/log/trace.log \
–verbose INFO -p 4730 -u root -d -t 4 \
–http-port=8080 \
-r http
–http-port=8080 指定监听端口号
-r http 起用 http 协议模块
调用方式:
目前 http 协议只支持任务提交类接口,其它类型的暂不支持。
按官方文档上说,http 支持 GET 和 POS 两种方式调用,但是 GET 方式我还没弄清楚怎样携带数据,POST 方式实验过是可以的
http://172.16.18.116:8080/reverse
reverse 就为函数名,假如 POST 的数据内容为:“Hello world!”,返回结果为:“!dlrow olleH”
在 http 的 header 头中可以设置一些任务参数:
* X-Gearman-Unique: <unique key>
* X-Gearman-Background: true
* X-Gearman-Priority: <high|low>
这种使用方式,实际上 gearmand 监听着两个端,原来的 4730 端还是可以接收正常的 gearman 协议客户端的请求,另外的 8080 端口则监听着 http 协议的请求,两种方式共同工作,http 服务前端如移动端调用,gearman 服务内部的其它模块的调用。
尝试用 Gearman 实现分布式处理(PHP)http://www.linuxidc.com/Linux/2011-12/50651.htm
用 Gearman 分发 PHP 应用程序的工作负载 http://www.linuxidc.com/Linux/2011-12/50650.htm
Gearman – 分布式远程过程处理框架 http://www.linuxidc.com/Linux/2011-12/50649.htm
学学 Gearman http://www.linuxidc.com/Linux/2011-12/50648.htm
CentOS 5.6 64 位下安装配置 Gearman http://www.linuxidc.com/Linux/2011-08/41456.htm
CentOS 的 Gearman 安装与使用无错版 http://www.linuxidc.com/Linux/2011-07/38947.htm