Skip to content

Commit 85cdf75

Browse files
committedJul 1, 2018
2.0.0
1 parent 54af53b commit 85cdf75

File tree

5 files changed

+528
-15
lines changed

5 files changed

+528
-15
lines changed
 

‎README.md

+76-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11

22
## Codeigniter Swoole Adapter
33

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.
59

610
With this adapter, you can start a task(CLI) any where(FPM) you want from your code.
711

@@ -17,7 +21,7 @@ composer require lanlin/codeigniter-swoole
1721

1822
## How to
1923

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.
2125
2. (this step is option) copy these two config files `swoole.php` and `timers.php` from `src/Helper` to your `application/config` folder.
2226
3. start swoole server `php index.php swoole/server/start`
2327
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
4246
So, that's all of it!
4347

4448

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-
5449
## Server CLI Commands
5550

5651
```shell
@@ -67,6 +62,76 @@ php index.php swoole/server/reload
6762
```
6863

6964

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+
70135
## License
71136

72137
This project is licensed under the MIT license.

‎src/Core/Server.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ public static function onTask(\Swoole\Server $serv, $taskId, $workerId, $data)
193193
{
194194
try
195195
{
196-
$argv =
196+
$_SERVER['argv'] =
197197
[
198-
0 => SELF['basename'],
198+
0 => SELF,
199199
1 => $data['route'],
200200
];
201201

202202
$_POST = $data['params'] ?? [];
203203

204-
require FCPATH . SELF['basename'];
204+
getCiSwooleConfig('starter');
205205
}
206206

207207
catch (\Throwable $e) { self::logs($e); }

0 commit comments

Comments
 (0)