diff --git a/bin/server b/bin/server deleted file mode 100755 index 9e57fd3..0000000 --- a/bin/server +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env php -run(); -?> \ No newline at end of file diff --git a/examples/client.php b/examples/client.php index a1be59b..89dd3ed 100644 --- a/examples/client.php +++ b/examples/client.php @@ -45,13 +45,9 @@ function remoteCall(string $host, $port, string $data) { return $ret['data']; } -$c = 0; -while(1){ -$c++; -$ret = remoteCall("127.0.0.1", "5188", '{"controller":"site","methor":"test","params":{"id":'.$c.',"status":0}}'); + +$ret = remoteCall("127.0.0.1", "5188", '{"controller":"site","methor":"test","params":{"id":1,"status":0}}'); echo "{$ret}\n"; -break; -} -//var_dump($ret); + ?> diff --git a/examples/jwt.php b/examples/jwt.php new file mode 100644 index 0000000..64ca2cd --- /dev/null +++ b/examples/jwt.php @@ -0,0 +1,41 @@ + "http://example.org", + "aud" => "http://example.com", + "iat" => 1356999524, + "nbf" => 1357000000 +); + +/** + * IMPORTANT: + * You must specify supported algorithms for your application. See + * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 + * for a list of spec-compliant algorithms. + */ +echo $jwt = JWT::encode($payload, $key); +$decoded = JWT::decode($jwt, $key, array('HS256')); + +print_r($decoded); + +/* + NOTE: This will now be an object instead of an associative array. To get + an associative array, you will need to cast it as such: +*/ + +$decoded_array = (array) $decoded; + +/** + * You can add a leeway to account for when there is a clock skew times between + * the signing and verifying servers. It is recommended that this leeway should + * not be bigger than a few minutes. + * + * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef + */ +JWT::$leeway = 60; // $leeway in seconds +$decoded = JWT::decode($jwt, $key, array('HS256')); + +?> \ No newline at end of file diff --git a/examples/rsa_test.php b/examples/rsa_test.php index 60a5dc0..c74a20d 100644 --- a/examples/rsa_test.php +++ b/examples/rsa_test.php @@ -36,164 +36,10 @@ EOD; $payload = [ - 'id' => 'backend', - 'basePath' => dirname(__DIR__), - 'controllerNamespace' => 'backend\controllers', - 'bootstrap' => ['log'], - 'components' => [ - 'assetManager' => [ - 'baseUrl' => '@web' . (getenv('KUBERNETES_NAMESPACE') ? '/' . getenv('KUBERNETES_NAMESPACE') : '') . '/assets' - ], - 'request' => [ - 'parsers' => [ - 'application/json' => 'yii\web\JsonParser', - ], - 'csrfParam' => '_csrf-api', - ], - 'user' => [ - 'identityClass' => 'backend\models\User', - 'enableAutoLogin' => true, - 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], - ], - 'session' => [ - // this is the name of the session cookie used for login on the app - 'name' => 'backend', - ], - 'log' => [ - 'traceLevel' => 1, - 'targets' => [ - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['error', 'warning'], - ], - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['info', 'error'], - 'categories' => ['imagetest'], - 'logFile' => '@app/runtime/logs/imagetest.log', - 'logVars' => [], - 'exportInterval' => 1, - 'prefix' => function ($message) { - - } - ], - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['error', 'warning', 'info'], - 'categories' => ['refund_log'], - 'logFile' => '@app/runtime/logs/refund_log.log', - 'logVars' => [], - 'exportInterval' => 1, - 'prefix' => function ($message) { - - } - ], - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['error', 'warning', 'info'], - 'categories' => ['obj'], - 'logFile' => '@app/runtime/logs/obj.log', - 'logVars' => [], - 'exportInterval' => 1, - 'prefix' => function ($message) { - - } - ], - ], - ], - 'errorHandler' => [ - 'errorAction' => 'site/error', - ], - 'urlManager' => [ - 'enablePrettyUrl' => true, - 'showScriptName' => false, - 'rules' => - getenv('KUBERNETES_NAMESPACE') ? [ - getenv('KUBERNETES_NAMESPACE') . '/' => '' - ] : [], - ], - 'goods' => ['class' => 'goods\goods\logic\goods\GoodsManager'], - ], - 'as access' => [ - 'class' => 'iron\components\AccessControl', - 'allowActions' => [ - 'site/catch-permission', - ] - ], - 'params' => [ - 'assetManager' => [ - 'baseUrl' => '@web' . (getenv('KUBERNETES_NAMESPACE') ? '/' . getenv('KUBERNETES_NAMESPACE') : '') . '/assets' - ], - 'request' => [ - 'parsers' => [ - 'application/json' => 'yii\web\JsonParser', - ], - 'csrfParam' => '_csrf-api', - ], - 'user' => [ - 'identityClass' => 'backend\models\User', - 'enableAutoLogin' => true, - 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], - ], - 'session' => [ - // this is the name of the session cookie used for login on the app - 'name' => 'backend', - ], - 'log' => [ - 'traceLevel' => 1, - 'targets' => [ - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['error', 'warning'], - ], - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['info', 'error'], - 'categories' => ['imagetest'], - 'logFile' => '@app/runtime/logs/imagetest.log', - 'logVars' => [], - 'exportInterval' => 1, - 'prefix' => function ($message) { - - } - ], - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['error', 'warning', 'info'], - 'categories' => ['refund_log'], - 'logFile' => '@app/runtime/logs/refund_log.log', - 'logVars' => [], - 'exportInterval' => 1, - 'prefix' => function ($message) { - - } - ], - [ - 'class' => 'yii\log\FileTarget', - 'levels' => ['error', 'warning', 'info'], - 'categories' => ['obj'], - 'logFile' => '@app/runtime/logs/obj.log', - 'logVars' => [], - 'exportInterval' => 1, - 'prefix' => function ($message) { - - } - ], - ], - ], - 'errorHandler' => [ - 'errorAction' => 'site/error', - ], - 'urlManager' => [ - 'enablePrettyUrl' => true, - 'showScriptName' => false, - 'rules' => - getenv('KUBERNETES_NAMESPACE') ? [ - getenv('KUBERNETES_NAMESPACE') . '/' => '' - ] : [], - ], - 'goods' => ['class' => 'goods\goods\logic\goods\GoodsManager'], - ], + "iss" => "deeplove.cn", + "name" => "nemo", + "age" => 29, + ]; $jwt = JWT::encode($payload, $privateKey, 'RS256'); diff --git a/src/RpcServer.php b/src/RpcServer.php index f27af06..0a846f2 100644 --- a/src/RpcServer.php +++ b/src/RpcServer.php @@ -62,9 +62,11 @@ class RpcServer extends BaseService { $ret = include $this->entryPoint; $this->send($fd, $ret); } catch (\Error $e) { + //TODO 记录日志 print_r($e); $this->send($fd, "YeeError"); } catch (\Exception $e) { + //TODO 记录日志 print_r($e); $this->send($fd, "YeeException"); } diff --git a/systemd/airpc.service b/systemd/airpc.service new file mode 100644 index 0000000..b0826d2 --- /dev/null +++ b/systemd/airpc.service @@ -0,0 +1,14 @@ +[Unit] +Description=AI Rpc Server +After=network.target +After=syslog.target + +[Service] +Type=simple +LimitNOFILE=65535 +ExecStart=/usr/bin/php {your server path} +ExecReload=/bin/kill -USR1 $MAINPID +Restart=always + +[Install] +WantedBy=multi-user.target graphical.target