Skip to content

Commit

Permalink
Merge pull request #111 from fucongcong/develop
Browse files Browse the repository at this point in the history
add rpc
  • Loading branch information
fucongcong committed Jun 1, 2016
2 parents 9059d96 + 4c5b5f5 commit 8890abb
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 7 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

[![Code Climate](https://codeclimate.com/repos/5657fbc8ea0d1f5571028f67/badges/c8175ffa03bd301eb7c7/gpa.svg)](https://codeclimate.com/repos/5657fbc8ea0d1f5571028f67/feed)
[![Build Status](https://travis-ci.org/fucongcong/Group.svg?branch=master)](https://travis-ci.org/fucongcong/Group)

#####version 1.2.4 rpc服务上线,cron脚本命令更新
#####version 1.2.3 合并swoole http server,优化cron,上线基本的async服务
#####version 1.2.2 定时服务多进程化了。优化了异步任务队列命令提示
#####version 1.2.1 支持了异步任务队列服务,轻松搞定高并发
#####[使用swoole http server性能测试报告](https://github.com/fucongcong/ssos/blob/master/php/group%E6%A1%86%E6%9E%B6%E6%B5%8B%E8%AF%95.md)

#####未来版本开发计划:
- 更轻量级化数据层与服务层
- rpc服务
- i18n支持
- 一些常用类库的丰富(中文转拼音,验证码,校验,过滤xss,tag...)

Expand Down Expand Up @@ -56,6 +55,7 @@ PHP交流QQ群:390536187
- [Log](#user-content-log)
- [Queue](#user-content-queue)
- [Test](#user-content-test)
- [RPC](#user-content-rpc)

####9.[单元测试](#user-content-单元测试)

Expand Down Expand Up @@ -654,7 +654,7 @@ class KernalResponseListener extends Listener
```
#####执行命令

app/cron start|restart|stop
app/cron start|restart|stop|status|exec (job name)

## Queue
#####异步队列服务介绍
Expand Down Expand Up @@ -706,6 +706,26 @@ class TestJob extends QueueJob
}
```
#####队列图形化管理工具[beanstalk_console](https://github.com/ptrofimov/beanstalk_console)

## RPC
#####依赖:[Swoole](https://github.com/swoole/swoole-src)
#####启用config/app.php 中的serviceProviders里面的RpcServiceProvider
#####配置config/rpc.php文件,
#####服务启动 php rpc_server.php &
#####服务热重启 php rpc_server.php -s reload
#####注意服务会默认开放src/Services下面所有服务的公有函数的调用
#####使用
```php

//指调用User模块下UserService 的getUser方法, 最后跟上参数
$res = \Rpc::call('User:User', 'getUser', [1]);
//错误返回false
var_dump($res);

```
#####用途,做soa服务化管理时。用于分布式。


## 单元测试

phpunit --bootstrap app/test.php src
1 change: 1 addition & 0 deletions app/async
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $app = new App();
$app -> initSelf();
$app -> doBootstrap($loader);
$app -> registerServices();
$app -> singleton('container') -> setAppPath(__ROOT__);

$async = new Async($argv);
$async -> run();
1 change: 1 addition & 0 deletions app/console
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $app = new App();
$app -> initSelf();
$app -> doBootstrap($loader);
$app -> registerServices();
$app -> singleton('container') -> setAppPath(__ROOT__);

$console = new Console($argv);
$console -> run();
1 change: 1 addition & 0 deletions app/cron
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $app = new App();
$app -> initSelf();
$app -> doBootstrap($loader);
$app -> registerServices();
$app -> singleton('container') -> setAppPath(__ROOT__);

$cron = new Cron($argv, $loader);
$cron -> run();
Expand Down
1 change: 1 addition & 0 deletions app/queue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $app = new App();
$app -> initSelf();
$app -> doBootstrap($loader);
$app -> registerServices();
$app -> singleton('container') -> setAppPath(__ROOT__);

$queue = new MessageQueue($argv, $loader);
$queue -> run();
4 changes: 3 additions & 1 deletion app/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Group\App\App;

$loader = require __DIR__.'/../vendor/autoload.php';

$loader->setUseIncludePath(true);

define('__ROOT__', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "../");

$app = new App();
$app -> initSelf();
$app -> doBootstrap($loader);
$app -> registerServices();
$app -> singleton('container') -> setAppPath(__ROOT__);
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"require": {
"php": ">=5.3",
"group/group-framework": "~1.1.8"
"hprose/hprose": "dev-master",
"group/group-framework": "~1.1.9"
}
}
10 changes: 10 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'Group\Routing\RouteServiceProvider',
'Group\EventDispatcher\EventDispatcherServiceProvider',
'Group\Queue\QueueServiceProvider',
//'Group\Rpc\RpcServiceProvider', //开启后提供rpc服务 需要安装swoole
],

//需要实例化的单例
Expand All @@ -42,4 +43,13 @@
//当使用swoole http server 时,需要指定host,port
'swoole_host' => '127.0.0.1',
'swoole_port' => 9777,
'swoole_setting' => [
'reactor_num' => 4,
'worker_num' => 25, //worker process num
'backlog' => 128, //listen backlog
'max_request' => 2000,
'heartbeat_idle_time' => 30,
'heartbeat_check_interval' => 10,
'dispatch_mode' => 3,
],
];
38 changes: 38 additions & 0 deletions config/rpc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
return [

'cache_dir' => 'runtime/rpc',

'current_server' => 'tcp',

'server' => [
//连接类型
'tcp' => [

'host' => '127.0.0.1',
'port' => '9396',
],

'http' => [

'host' => '127.0.0.1',
'port' => '9397',
],

'ws' => [

'host' => '127.0.0.1',
'port' => '9394',
],
],

'setting' => [
'reactor_num' => 4,
'worker_num' => 25, //worker process num
'backlog' => 128, //listen backlog
'max_request' => 2000,
'heartbeat_idle_time' => 30,
'heartbeat_check_interval' => 10,
'dispatch_mode' => 3,
],
];
8 changes: 8 additions & 0 deletions rpc_server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

define('__ROOT__', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
require_once __ROOT__.'vendor/hprose/hprose/src/Hprose.php';
require_once __ROOT__.'vendor/group/group-framework/core/Group/RpcKernal.php';

$kernal = new RpcKernal('tcp');
$kernal->init();
2 changes: 1 addition & 1 deletion src/Services/User/Impl/UserServiceImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UserServiceImpl extends UserBaseService implements UserService

public function getUser($id)
{
return 2;
return 3;
}

}
4 changes: 3 additions & 1 deletion src/Web/Controller/Group/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public function addAction()
}

public function testAction(Request $request, $id)
{
{
var_dump(\Rpc::call('User:User', 'getUser', [1]));

// \Log::debug('123',['user'=>1]);
// \Log::debug('1233',['user'=>12]);
// \Log::debug('12asdasd33',['user'=>555]);
Expand Down

0 comments on commit 8890abb

Please sign in to comment.