-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.php
80 lines (65 loc) · 1.94 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
if( 'cli' !== php_sapi_name() ){
exit( '服务只能运行在cli sapi模式下'.PHP_EOL );
}
if( !extension_loaded('swoole') ){
exit( '请安装swoole扩展'.PHP_EOL );
}
// 定义系统常量
define( 'DS', DIRECTORY_SEPARATOR );
define( 'ROOT', __DIR__.DS );
// 载入系统函数库
require_once ROOT."System".DS."Library".DS."Function.php";
if( is_file( ROOT.'vendor'.DS.'autoload.php' ) ){
require_once ROOT.'vendor'.DS.'autoload.php';
}
else {
// 自定义autoload方法
function autoload( $class ){
$includePath = str_replace( '\\', DS, $class );
$targetFile = ROOT.$includePath.'.php';
require_once( $targetFile );
}
spl_autoload_register( 'autoload' );
}
// 继承Core父类
class Gmu extends System\Core{
// 拉起worker进程前需要做的初始化工作
public function initWorker(){}
// 拉起tasker进程前需要做的初始化工作
// 比如初始化数据库类库
// 比如初始化其他类库
public function initTasker( \swoole_server $server, $workerId ){
$di = \System\Component\Di::getInstance();
}
// 具体业务逻辑
public function process( $server, $param ){
// 将param抛给model中的method,并获得到处理完后的数据
$targetModel = '\Application\\Controller\\'.ucfirst( $param['param']['model'] );
$targetModel = new $targetModel;
$targetConfig['param'] = $param['param']['param'];
$sendData = call_user_func_array( array( $targetModel, $param['param']['method'] ), array( $targetConfig ) );
return $sendData;
}
}
$gmu = new Gmu;
// 开启一些配置项
$gmu->initSetting( array(
'http' => array(
'host' => '0.0.0.0',
'port' => 6666,
),
'tcp' => array(
'port' => 6667,
),
'custom' => array(
'tcpPack' => 'length', // 1.eof,eof拆包 2.length,length拆包
),
// 服务注册
'serviceRegisterSetting' => array(
'host' => '127.0.0.1',
'port' => 6379,
'serviceName' => 'account-service',
),
) );
$gmu->run();