Skip to content

Commit a8a6251

Browse files
committed
Update README.md
1 parent 58fddd5 commit a8a6251

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

README.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
<br>
77
</p>
88

9-
CodeIgniter 3 Queue Worker Management Controller
9+
CodeIgniter 3 Daemon Queue Worker Management Controller
1010

1111
[![Latest Stable Version](https://poser.pugx.org/yidas/codeigniter-queue-worker/v/stable?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-queue-worker)
12-
[![Latest Unstable Version](https://poser.pugx.org/yidas/codeigniter-queue-worker/v/unstable?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-queue-worker)
1312
[![License](https://poser.pugx.org/yidas/codeigniter-queue-worker/license?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-queue-worker)
1413

1514
This Queue Worker extension is collected into [yidas/codeigniter-pack](https://github.com/yidas/codeigniter-pack) which is a complete solution for Codeigniter framework.
1615

16+
> This library only provides worker controller, you need to implement your own queue driver with handler/process in it.
17+
1718
Features
1819
--------
1920

2021
- ***Multi-Processing** implementation on native PHP-CLI*
2122

22-
- ***Dynamically Workers dispatching** management*
23+
- ***Dynamically Workers dispatching (Daemon)** management*
2324

2425
- ***Running in background permanently** without extra libraries*
2526

@@ -54,7 +55,7 @@ OUTLINE
5455
DEMONSTRATION
5556
-------------
5657

57-
Running a listener with 2~5 workers setting added per 3 seconds:
58+
Running a listener (Daemon) with 2~5 workers setting added per 3 seconds:
5859

5960
```
6061
$ php index.php job_controller/listen
@@ -72,10 +73,18 @@ $ php index.php job_controller/listen
7273
INTRODUCTION
7374
------------
7475

75-
This library provides a Queue Worker total solution for Codeigniter 3 framework, which includes Listener and Worker for processing new jobs from queue. You may integrate your application queue (such as Redis) with Queue Worker Controller.
76+
This library provides a Daemon Queue Worker total solution for Codeigniter 3 framework with Multi-Processes implementation, it includes Listener (Daemon) and Worker for processing new jobs from queue. You may integrate your application queue (such as Redis) with Queue Worker Controller.
77+
78+
PHP is a lack of support for multithreading at the core language level, this library implements multithreading by managing multiprocessing.
79+
80+
For more concepts, the following diagram shows the implementation structure of this library:
81+
82+
<img src="https://raw.githubusercontent.com/yidas/codeigniter-queue-worker/master/img/introduction-structure.png" />
7683

77-
Listener could continue to run for detecting new jobs until it is manually stopped or you close your terminal. On the other hand
78-
, Worker could continue to run for processing new jobs until there is no job left.
84+
Listener (Daemon) could continue to run for detecting new jobs until it is manually stopped or you close your terminal. On the other hand
85+
, Worker could continue to run for processing new jobs until there is no job left, which the workers could be called by Listener.
86+
87+
Launcher is suitable for launching a listener process, which the running Listener process could be unique that the second launch would detect existent listener and do NOT launch again.
7988

8089
---
8190

@@ -108,7 +117,7 @@ $config['composer_autoload'] = TRUE;
108117
CONFIGURATION
109118
-------------
110119

111-
You need to design handlers for your own worker inherited from this library, there are common interfaces as following:
120+
First, create a controller that extends the working controller, and then use your own queue driver to design your own handler to implement the worker controller. There are common interfaces as following:
112121

113122
```php
114123
use yidas\queue\worker\Controller as WorkerController;
@@ -126,7 +135,7 @@ class My_worker extends WorkerController
126135
}
127136
```
128137

129-
These handlers are supposed to be designed for detecting the same job queue, but for different purpose. For example, Listener and Worker detect the same Redis list queue, Listener only do dispatching jobs by forking Worker, while Worker continue to takes out jobs and do the processing until job queue is empty.
138+
These handlers are supposed to be designed for detecting the same job queue, but for different purpose. For example, if you are using Redis as message queue, Listener and Worker detect the same Redis list queue, Listener only do dispatching jobs by forking Worker, while Worker continue to takes out jobs and do the processing until job queue is empty.
130139

131140
### How to Design a Worker
132141

@@ -144,15 +153,14 @@ class My_worker extends \yidas\queue\worker\Controller
144153
{
145154
protected function init()
146155
{
147-
// Optional autoload
156+
// Optional autoload (Load your own libraries or models)
148157
$this->load->library('myjobs');
149-
150-
// Optional shared properties setting
151-
$this->static = 'static value';
152158
}
153159
// ...
154160
```
155161

162+
> As above, `myjobs` library is defined by your own application which handles your job processes.
163+
156164
#### 2. Build Worker
157165

158166
```php
@@ -167,15 +175,17 @@ class My_worker extends \yidas\queue\worker\Controller
167175
{
168176
protected function handleWork()
169177
{
178+
// Your own method to get a job from your queue in the application
170179
$job = $this->myjobs->popJob();
171180

172-
// `false` for job not found, which would close the worker itself.
181+
// return `false` for job not found, which would close the worker itself.
173182
if (!$job)
174183
return false;
175184

185+
// Your own method to process a job
176186
$this->myjobs->processJob($job);
177187

178-
// `true` for job existing, which would keep handling.
188+
// return `true` for job existing, which would keep handling.
179189
return true;
180190
}
181191
// ...
@@ -195,8 +205,9 @@ class My_worker extends \yidas\queue\worker\Controller
195205
{
196206
protected function handleListen()
197207
{
198-
// `true` for job existing, which leads to dispatch worker(s).
199-
// `false` for job not found, which would keep detecting new job
208+
// Your own method to detect job existence
209+
// return `true` for job existing, which leads to dispatch worker(s).
210+
// return `false` for job not found, which would keep detecting new job
200211
return $this->myjobs->exists();
201212
}
202213
// ...
@@ -241,7 +252,7 @@ USAGE
241252

242253
There are 3 actions for usage:
243254

244-
- `listen` A listener to manage and dispatch jobs by forking workers.
255+
- `listen` A listener (Daemon) to manage and dispatch jobs by forking workers.
245256
- `work` A worker to process and solve jobs from queue.
246257
- `launch` A launcher to run `listen` or `work` process in background and keep it running uniquely.
247258

src/Controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*
1111
* @author Nick Tsai <[email protected]>
1212
* @version 1.0.0
13+
* @todo Implement by using pcntl
1314
*/
1415
class Controller extends CI_Controller
1516
{

0 commit comments

Comments
 (0)