forked from LinkedDestiny/swoole-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f04d74
commit 1270ef4
Showing
1 changed file
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,4 +134,33 @@ public function onTask($serv,$task_id,$from_id, $data) { | |
[点此查看完整服务端代码](https://github.com/LinkedDestiny/swoole-doc/blob/master/src/03/swoole_mysql_pool_server.php)<br> | ||
[点此查看完整客户端代码](https://github.com/LinkedDestiny/swoole-doc/blob/master/src/03/swoole_mysql_pool_client.php)<br> | ||
|
||
下章预告:Swoole多端口监听、热重启以及Timer进阶:简单crontab | ||
##**4.Task实战:yii中应用task** | ||
在YII框架中结合了swoole 的task 做了异步处理。 | ||
本例中 主要用到 | ||
1、protected/commands/ServerCommand.php 用来做server。 | ||
2、protected/event/下的文件 这里是在异步中的具体实现。 | ||
|
||
客户端调用参照 TestController | ||
```php | ||
<?php | ||
class TestController extends Controller{ | ||
public function actionTT(){ | ||
$message['uid'] = 2; | ||
$message['email'] = '[email protected]'; | ||
$message['title'] = '接口报警邮件'; | ||
$message['contents'] = "'EmailEvent'接口请求过程出错! 错误信息如下:err_no:'00000' err_msg:'测试队列' 请求参数为:'[]'"; | ||
$message['type'] = 2; | ||
|
||
$data['param'] = $message; | ||
$data['class'] = 'Email'; | ||
$client = new EventClient(); | ||
$data = $client->send($data); | ||
} | ||
} | ||
?> | ||
``` | ||
|
||
有个task表是用来记录异步任务的。如果失败重试3次。sql在protected/data/sql.sql里。 | ||
[点此查看完整客户端代码](https://github.com/LinkedDestiny/swoole-doc/blob/master/src/03/swoole_mysql_pool_client.php)<br> | ||
|
||
下章预告:Swoole多端口监听、热重启以及Timer进阶:简单crontab |