|
1 | 1 | backq
|
2 | 2 | =====
|
3 | 3 |
|
4 |
| -Perform tasks with workers & publishers (queues) |
| 4 | +Background tasks with workers & publishers via queues |
5 | 5 |
|
6 |
| -* [APNS](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9) Push notifications sending |
7 |
| -* asynchronous process executon via [proc_open](http://php.net/manual/en/function.proc-open.php) implemented by [symfony/process](http://symfony.com/doc/current/components/process.html) component |
| 6 | +* Sending [APNS](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9) push notifications (Legacy API) |
| 7 | +* Sending [FCM](https://firebase.google.com/docs/cloud-messaging) push notifications to Android (GCM/FCM) |
| 8 | +* Sending [AWS SNS](https://aws.amazon.com/sns/) push notifications via AWS SNS arn's |
| 9 | +* Executing [Psr7\Request](https://www.php-fig.org/psr/psr-7/) asynchronously via Guzzle |
| 10 | +* Executing **any** processes with [symfony/process](http://symfony.com/doc/current/components/process.html) |
| 11 | +* [Long delay scheduling](https://aws.amazon.com/blogs/aws/new-manage-dynamodb-items-using-time-to-live-ttl/) via DynamoSQS Adapter and Serialized worker, for reliable long-term scheduled jobs |
| 12 | +* Extendable - write your own worker and use existing adapters out of the box ... |
8 | 13 |
|
9 | 14 | #### Installation
|
10 | 15 | ```
|
11 |
| -#composer self-update |
12 |
| -#composer clear-cache |
13 |
| -#composer diagnose |
14 |
| -composer require sshilko/backq:^1.9 |
| 16 | +#composer self-update && composer clear-cache && composer diagnose |
| 17 | +composer require sshilko/backq:^2.0 |
15 | 18 | ```
|
16 | 19 |
|
17 |
| -#### Requirements |
| 20 | +#### Supported queue servers |
18 | 21 |
|
19 |
| -* Recommended [PHP >=7.0.4](https://launchpad.net/~ondrej/+archive/ubuntu/php) |
20 |
| -* Required PHP 5.5 ([generators](http://php.net/manual/en/language.generators.overview.php) & coroutines) |
21 |
| -* Simple & Fast work queue [Beanstalkd](https://github.com/kr/beanstalkd/blob/master/doc/protocol.txt) davidpersson/beanstalk [library](https://github.com/davidpersson/beanstalk) |
| 22 | +* [Beanstalkd](https://github.com/kr/beanstalkd/blob/master/doc/protocol.txt) |
| 23 | +* [Redis](https://redis.io) |
| 24 | +* [NSQ](https://nsq.io) |
| 25 | +* [DynamoDB](https://aws.amazon.com/dynamodb/) [SQS](https://aws.amazon.com/sqs/) [Lambda](https://aws.amazon.com/lambda/) for DynamoSQS adapter |
22 | 26 |
|
23 |
| -#### Push notifications requirements |
| 27 | +#### Features |
24 | 28 |
|
25 |
| -* Basic idea inspired by [ApnsPHP](https://packagist.org/packages/duccio/apns-php) [original](https://code.google.com/archive/p/apns-php/) but because package was not maintained for long time, own adapter was implemented (TLS support, payload size >= 256 in iOS8+, fwrite()/fread() error handlind, etc.). |
| 29 | +Workers compatibility with adapters |
26 | 30 |
|
27 |
| -#### Process dispatch requirements |
28 |
| - |
29 |
| -* Processes are spawned via [symfony/process](http://symfony.com/doc/current/components/process.html) component |
30 |
| - |
31 |
| -#### Licence |
32 |
| -[MIT](http://opensource.org/licenses/MIT) |
| 31 | +| Adapter / Worker |[FCM](https://firebase.google.com/docs/cloud-messaging)|[APNS](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9)|[Process](http://symfony.com/doc/current/components/process.html)|[Guzzle](https://www.php-fig.org/psr/psr-7/)|Serialized| |
| 32 | +|----|---|---|---|---|---| |
| 33 | +| [Beanstalkd](https://beanstalkd.github.io/) | + | + | + | + | + | |
| 34 | +| [Redis](https://redis.io) | + | + | + | + | ? | |
| 35 | +| [NSQ](https://nsq.io/) | + | + | + | + | ? | |
| 36 | +| [DynamoSQS](https://aws.amazon.com/) | + | + | + | + | + | |
33 | 37 |
|
34 |
| -#### Review |
| 38 | +Adapter implemented features |
35 | 39 |
|
36 |
| -[Blog post about sending Apple push notifications](http://moar.sshilko.com/2014/09/09/APNS-Workers/) |
| 40 | +| Adapter / Feature | ping | hasWorkers | setWorkTimeout | |
| 41 | +|---|---|---|---| |
| 42 | +| [Beanstalkd](https://beanstalkd.github.io/) | + | + | + |
| 43 | +| [Redis](https://redis.io) | + | - | + |
| 44 | +| [NSQ](https://nsq.io/) | + | - | * |
| 45 | +| [DynamoSQS](https://aws.amazon.com/) | - | - | + |
37 | 46 |
|
38 |
| -#### API / Basic Usage / APNS push notifications |
| 47 | +Worker available features |
39 | 48 |
|
40 |
| -Initialize Queue adapter |
| 49 | +- `setRestartThreshold` (limit max number of jobs cycles, then terminate) |
| 50 | +- `setIdleTimeout` (limit max idle time, then terminating) |
41 | 51 |
|
42 |
| -* Adapter for Beanstalkd |
43 |
| -``` |
44 |
| -/** |
45 |
| - * only Beanstalk is supported atm. |
46 |
| - * Recommended: default settings expect server at 127.0.0.1:11300 with non-persistent connection |
47 |
| - */ |
48 |
| -$adapter = new \BackQ\Adapter\Beanstalk; |
49 |
| -//$custom = new \BackQ\Adapter\Beanstalk($host, $port, $timeout, $persistent); |
50 |
| -``` |
| 52 | +TLDR |
51 | 53 |
|
52 |
| -* Worker (can have multiple per same queue) that dispatches messages |
| 54 | + |
53 | 55 |
|
54 |
| -``` |
55 |
| -$ca = 'somepath/entrust_2048_ca.cer'; |
56 |
| -$pem = 'somepath/apnscertificate.pem'; |
57 |
| -$env = \ApnsPHP_Abstract::ENVIRONMENT_SANDBOX; |
58 |
| -
|
59 |
| -$worker = new \BackQ\Worker\Apnsd($adapter); |
60 |
| -
|
61 |
| -/** |
62 |
| - * We can listen to custom queue and have multiple queues & multiple workers per queue |
63 |
| - * @optional |
64 |
| - */ |
65 |
| -$worker->setQueueName($worker->getQueueName() . 'myQueueName1'); |
66 |
| -
|
67 |
| -/** |
68 |
| - * The longer we wait |
69 |
| - * the less chance that we will send push into closed socket (eof) |
70 |
| - * @optional |
71 |
| - */ |
72 |
| -$worker->socketSelectTimeout = \BackQ\Worker\Apnsd::SENDSPEED_TIMEOUT_RECOMMENDED; |
73 |
| -
|
74 |
| -$worker->setLogger(new \BackQ\Logger('somepath/logfile.txt')); |
75 |
| -
|
76 |
| -$worker->setRootCertificationAuthority($ca); |
77 |
| -$worker->setCertificate($pem); |
78 |
| -$worker->setEnvironment($env); |
79 |
| -
|
80 |
| -/** |
81 |
| - * Output basic debug |
82 |
| - */ |
83 |
| -//$worker->toggleDebug(true); |
84 |
| -
|
85 |
| -/** |
86 |
| - * Quit the worker after processing 1000 pushes |
87 |
| - * @optional |
88 |
| - */ |
89 |
| -$worker->setRestartThreshold(1000); |
90 |
| -
|
91 |
| -/** |
92 |
| - * Quit the worker if no jobs received for 600 seconds |
93 |
| - * @optional |
94 |
| - */ |
95 |
| -$worker->setIdleTimeout(600); |
96 |
| -
|
97 |
| -/** |
98 |
| - * Set stream_set_timeout() for stream_socket_client() |
99 |
| - * @optional |
100 |
| - */ |
101 |
| -$worker->readWriteTimeout = 5; |
102 |
| -
|
103 |
| -/** |
104 |
| - * Workaround for |
105 |
| - * PHP 5.5.23,5.5.24 & 5.6.7,5.6.8 |
106 |
| - * does not honor the stream_set_timeout() |
107 |
| - * @see https://bugs.php.net/bug.php?id=69393 |
108 |
| - */ |
109 |
| -//$worker->connectTimeout = 2; |
110 |
| -
|
111 |
| -$worker->run(); |
112 |
| -``` |
113 |
| - |
114 |
| -* Publisher pushes new messages into Beanstalkd queue |
| 56 | +See [/example](https://github.com/sshilko/backq/tree/master/example) folder for usage examples |
115 | 57 |
|
116 |
| -``` |
117 |
| -$publisher = \BackQ\Publisher\Apnsd::getInstance(new \BackQ\Adapter\Beanstalk); |
118 |
| -
|
119 |
| -/** |
120 |
| - * We can publish to custom queue |
121 |
| - * @optional |
122 |
| - */ |
123 |
| -$publisher->setQueueName($worker->getQueueName() . 'myQueueName1'); |
124 |
| -
|
125 |
| -/** |
126 |
| - * Give 4 seconds to dispatch the message (time to run) |
127 |
| - * Unless worker reports successfuly that job is done, the job is put back into "ready" state |
128 |
| - * @optional |
129 |
| - */ |
130 |
| -$params = array(\BackQ\Adapter\Beanstalk::PARAM_JOBTTR => 4); |
131 |
| -
|
132 |
| -/** |
133 |
| - * Delay sending push by 10 seconds |
134 |
| - * @optional |
135 |
| - */ |
136 |
| -$params[\BackQ\Adapter\Beanstalk::PARAM_READYWAIT] = 10; |
137 |
| -
|
138 |
| -/** |
139 |
| - * Ensure adapter can connect to Beanstalk & has workers WAITING for the job |
140 |
| - */ |
141 |
| -if ($publisher->start() && $publisher->hasWorkers()) { |
142 |
| - /** |
143 |
| - * Original ApnsPHP messages supported, recommended customized \BackQ\Message\ApnsPHP |
144 |
| - */ |
145 |
| - $messages = array(); |
146 |
| - for ($i=0; $i < count($messages); $i++) { |
147 |
| - $result = $publisher->publish($messages[$i], $params); |
148 |
| - if ($result > 0) { |
149 |
| - /** |
150 |
| - * successfully added to dispatch queue |
151 |
| - */ |
152 |
| - } else { |
153 |
| - /** |
154 |
| - * Fallback here |
155 |
| - */ |
156 |
| - } |
157 |
| - } |
158 |
| -} else { |
159 |
| - /** |
160 |
| - * Fallback here |
161 |
| - * |
162 |
| - * + Unable to connect to Beanstalk |
163 |
| - * + No workers currently waiting for job (all of them busy processing or none launched) |
164 |
| - */ |
165 |
| -} |
166 |
| -``` |
| 58 | +#### Old version 1 detailed review |
167 | 59 |
|
168 |
| -#### Basic usage (processes) |
169 |
| - |
170 |
| -A queue for the [symfony/process](http://symfony.com/doc/current/components/process.html) component usage. |
171 |
| -A simple scheduler is done using Beanstalkd `delay` option for jobs. Or just dispatch projess jobs for async execution. |
172 |
| - |
173 |
| -Worker daemon |
174 |
| -``` |
175 |
| -$worker = new \BackQ\Worker\AProcess(new \BackQ\Adapter\Beanstalk); |
176 |
| -$worker->run(); |
177 |
| -``` |
| 60 | +[Blog post about sending Apple push notifications](http://moar.sshilko.com/2014/09/09/APNS-Workers/) |
178 | 61 |
|
179 |
| -Publisher |
180 |
| -``` |
181 |
| -$publisher = \BackQ\Publisher\Process::getInstance(new \BackQ\Adapter\Beanstalk); |
182 |
| -if ($publisher->start() && $publisher->hasWorkers()) { |
183 |
| - $message = new \BackQ\Message\Process('echo $( date +%s ) >> /tmp/test'); |
184 |
| - $result = $publisher->publish($message, array(\BackQ\Adapter\Beanstalk::PARAM_JOBTTR => 3, |
185 |
| - \BackQ\Adapter\Beanstalk::PARAM_READYWAIT => 4)); |
186 |
| - if ($result > 0) { |
187 |
| - //Async process job added to queue |
188 |
| - } else { |
189 |
| - //fail |
190 |
| - } |
191 |
| -} |
192 |
| -``` |
| 62 | +#### Licence |
| 63 | +MIT |
193 | 64 |
|
194 |
| -#### Master-dev |
| 65 | +Copyright 2013-2019 Sergei Shilko |
195 | 66 |
|
196 |
| -Please use only stable (>=1.1.2) versions, everyone <= 1.1.2 should update for latest bugfixes around sockets io. |
197 | 67 |
|
0 commit comments