1
1
2
2
## Codeigniter Swoole Adapter
3
3
4
- This adapter would make it easy to using swoole within Codeigniter framework.
4
+ You want long-run task? timers? FPM to CLI? Code reusing in both FPM & CLI mode?
5
+
6
+ "It's so easy!"
7
+
8
+ This adapter would make it so easy to using swoole within Codeigniter framework.
5
9
6
10
With this adapter, you can start a task(CLI) any where(FPM) you want from your code.
7
11
@@ -17,7 +21,7 @@ composer require lanlin/codeigniter-swoole
17
21
18
22
## How to
19
23
20
- 1 . first, of course you must install ` codeigniter-swoole ` in your codeigniter project.
24
+ 1 . first, of course you must install ` codeigniter-swoole ` to your codeigniter project.
21
25
2 . (this step is option) copy these two config files ` swoole.php ` and ` timers.php ` from ` src/Helper ` to your ` application/config ` folder.
22
26
3 . start swoole server ` php index.php swoole/server/start `
23
27
4 . you can use ` \CiSwoole\Core\Client::send($data) ` to start a task now!
@@ -42,15 +46,6 @@ The `route` is used for find which method to be call as a task, and `params` is
42
46
So, that's all of it!
43
47
44
48
45
- ## A little more
46
-
47
- The step 2 copied files were config files for this adapter.
48
-
49
- ` swoole.php ` file can set host, port, log file and so on.
50
-
51
- ` timers.php ` file can set some timer methods for swoole server, these timers will be started once the server inited.
52
-
53
-
54
49
## Server CLI Commands
55
50
56
51
``` shell
@@ -67,6 +62,76 @@ php index.php swoole/server/reload
67
62
```
68
63
69
64
65
+ ## A little more
66
+
67
+ The step 2 copied files were config files for this adapter.
68
+
69
+ ` swoole.php ` file can set host, port, log file and so on.
70
+
71
+ ` timers.php ` file can set some timer methods for swoole server, these timers will be started once the server inited.
72
+
73
+ You can copy ` tests/application ` to your ` application ` for testing. The demos are same as below shows.
74
+
75
+
76
+ ``` php
77
+ class Test extends CI_Controller
78
+ {
79
+
80
+ // ------------------------------------------------------------------------------
81
+
82
+ /**
83
+ * here's the task 'tests/test/task'
84
+ */
85
+ public function task()
86
+ {
87
+ $data = $this->input->post(); // as you see, params worked like normally post data
88
+
89
+ log_message('info', var_export($data, true));
90
+ }
91
+
92
+ // ------------------------------------------------------------------------------
93
+
94
+ /**
95
+ * here's the timer method
96
+ *
97
+ * you should copay timers.php to your config folder,
98
+ * then add $timers['tests/test/task_timer'] = 10000; and start the swoole server.
99
+ *
100
+ * this method would be called every 10 seconds per time.
101
+ */
102
+ public function task_timer()
103
+ {
104
+ log_message('info', 'timer works!');
105
+ }
106
+
107
+ // ------------------------------------------------------------------------------
108
+
109
+ /**
110
+ * send data to task
111
+ */
112
+ public function send()
113
+ {
114
+ try
115
+ {
116
+ \CiSwoole\Core\Client::send(
117
+ [
118
+ 'route' => 'tests/test/task',
119
+ 'params' => ['hope' => 'it works!'],
120
+ ]);
121
+ }
122
+ catch (\Exception $e)
123
+ {
124
+ log_message('error', $e->getMessage());
125
+ log_message('error', $e->getTraceAsString());
126
+ }
127
+ }
128
+
129
+ // ------------------------------------------------------------------------------
130
+
131
+ }
132
+ ```
133
+
134
+
70
135
## License
71
136
72
137
This project is licensed under the MIT license.
0 commit comments