-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathREADME
116 lines (90 loc) · 3.07 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
BEANSTALK
---- Minimalistic PHP client for beanstalkd.
Synopsis
--------
This library allows you to interface with the beanstalkd[1] work queue and is
built with a minimal featureset still supporting the complete protocol. The
main (and currently only) class can be found at `src/Client.php`.
The class was formerly part of the queue plugin for CakePHP[2]. It has been
extracted for higher reusability in other places and frameworks.
Cute[3] is such a project. It uses this library to provide convenient
access and tooling around the work queue for PHP.
[1] http://kr.github.com/beanstalkd
[2] https://github.com/davidpersson/queue
[3] https://github.com/atelierdisko/cute_php
Copyright & License
-------------------
Beanstalk, a beanstalk PHP client library for the beanstalkd work queue is
Copyright (c) 2009-2015 David Persson if not otherwise stated. The code
is distributed under the terms of the MIT License. For the full license
text see the LICENSE file.
Versions & Requirements
-----------------------
1.0.0, PHP >=5.2.1
1.1.0, PHP >=5.2.1
2.0.0, PHP >=5.4.1
Note: In PHP Versions 5.3.9, 5.3.10 and 5.4.0 the `stream_get_line()`
function exhibits buggy behavior (PHP bug #60817), thus
these versions cannot be used with this library.
Installation
------------
The preferred installation method is via composer. You can add the library
as a dependency via:
$ composer require davidpersson/beanstalk
Usage
-----
<?php
use Beanstalk\Client;
//
// A sample producer.
//
$beanstalk = new Client(); // For connection options see the
// class documentation.
$beanstalk->connect();
$beanstalk->useTube('flux'); // Begin to use tube `'flux'`.
$beanstalk->put(
23, // Give the job a priority of 23.
0, // Do not wait to put job into the ready queue.
60, // Give the job 1 minute to run.
'/path/to/cat-image.png' // The job's body.
);
$beanstalk->disconnect();
//
// A sample consumer.
//
$beanstalk = new Client();
$beanstalk->connect();
$beanstalk->watch('flux');
while (true) {
$job = $beanstalk->reserve(); // Block until job is available.
// Now $job is an array which contains its ID and body:
// ['id' => 123, 'body' => '/path/to/cat-image.png']
// Processing of the job...
$result = touch($job['body']);
if ($result) {
$beanstalk->delete($job['id']);
} else {
$beanstalk->bury($job['id']);
}
}
// When exiting i.e. on critical error conditions
// you may also want to disconnect the consumer.
// $beanstalk->disconnect();
?>
Running the Tests
-----------------
The integration tests contained in this library require a running beanstalkd
instance. You'll need to start a dedicated instance on port 11301 as follows.
```
beanstalkd -VV -l 127.0.0.1 -p 11301
```
Tests for this library are PHPUnit based. To run the tests you'll need
to have PHPUnit installed[1]. Following commands will run all the tests.
```
cd /path/to/beanstalk
composer install
export TEST_BEANSTALKD_HOST=127.0.0.1
export TEST_BEANSTALKD_PORT=11301
vendor/bin/phpunit tests
```
[1] http://www.phpunit.de/manual/current/en/installation.html