Skip to content

Commit

Permalink
在task章节中增加与yii框架结合的实例
Browse files Browse the repository at this point in the history
  • Loading branch information
reallovelei committed May 25, 2015
1 parent 9f04d74 commit 1270ef4
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1270ef4

Please sign in to comment.