forked from brianlmoon/net_gearman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
60 lines (40 loc) · 1.58 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Net_Gearman
About
Net_Gearman is a PEAR package for interfacing with Danga's Gearman. Gearman is a system to farm out work to other machines, dispatching function calls to machines that are better suited to do work, to do work in parallel, to load balance lots of function calls, or to call functions between languages.
Installation
1. Install PEAR if it is not already installed on your system.
2. Use git to pull this repo to your servers. Be sure where you install it is in the autoload or include path before the rest of PEAR.
Examples
Client
<?php
require_once 'Net/Gearman/Client.php';
$client = new Net_Gearman_Client('localhost:7003');
$client->someBackgroundJob(array(
'userid' => 5555,
'action' => 'new-comment'
));
?>
Job
<?php
class Net_Gearman_Job_someBackgroundJob extends Net_Gearman_Job_Common
{
public function run($args)
{
if (!isset($args['userid']) || !isset($args['action'])) {
// Throw a Net_Gearman_Job_Exception to report back to the server that the job failed.
throw new Net_Gearman_Job_Exception('Invalid/Missing arguments');
}
// Insert a record or something based on the $args
return array(); // Results are returned to Gearman, except for
// background jobs like this one.
}
}
?>
Worker
For easiest use, use GearmanManager for running workers. See: https://github.com/brianlmoon/GearmanManager
<?php
require_once 'Net/Gearman/Worker.php';
$worker = new Net_Gearman_Worker('localhost:7003');
$worker->addAbility('someBackgroundJob');
$worker->beginWork();
?>