From 8f02304febb9c2e857d0f95bb9915f00def03d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Wed, 1 Aug 2018 11:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9D=9Eserver=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=E4=BD=BF=E7=94=A8rpc=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=97=B6=E6=8A=9B=E5=87=BACall=20to=20a=20member=20function=20?= =?UTF-8?q?getTcpSetting()=20on=20null=20=E7=9A=84BUG=20(https://github.co?= =?UTF-8?q?m/swoft-cloud/swoft-component/pull/155)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Packer/EofTrait.php | 13 +++----- test/Cases/JsonPackerTest.php | 5 +++ test/config/server.php | 62 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 test/config/server.php diff --git a/src/Packer/EofTrait.php b/src/Packer/EofTrait.php index 6c1a7f6..e74b5a4 100644 --- a/src/Packer/EofTrait.php +++ b/src/Packer/EofTrait.php @@ -14,14 +14,9 @@ trait EofTrait /** * @return string */ - public function getEof():string + public function getEof(): string { - $eof = ''; - $tcpSettings = App::$server->getTcpSetting(); - if (isset($tcpSettings['package_eof'])) { - $eof = $tcpSettings['package_eof']; - } - return $eof; + $properties = App::getAppProperties(); + return $properties->get('server.tcp.package_eof', ''); } - -} \ No newline at end of file +} diff --git a/test/Cases/JsonPackerTest.php b/test/Cases/JsonPackerTest.php index 89d3f00..84b02a0 100644 --- a/test/Cases/JsonPackerTest.php +++ b/test/Cases/JsonPackerTest.php @@ -37,4 +37,9 @@ public function pack() $this->assertJson(\json_encode($data), $packedData); } + public function testEof() + { + $packer = new JsonPacker(); + $this->assertEquals("\r\n", $packer->getEof()); + } } \ No newline at end of file diff --git a/test/config/server.php b/test/config/server.php new file mode 100644 index 0000000..7efbbed --- /dev/null +++ b/test/config/server.php @@ -0,0 +1,62 @@ + [ + 'pfile' => env('PFILE', '/tmp/swoft.pid'), + 'pname' => env('PNAME', 'php-swoft'), + 'tcpable' => env('TCPABLE', true), + 'cronable' => env('CRONABLE', false), + 'autoReload' => env('AUTO_RELOAD', true), + ], + 'tcp' => [ + 'host' => env('TCP_HOST', '0.0.0.0'), + 'port' => env('TCP_PORT', 8099), + 'mode' => env('TCP_MODE', SWOOLE_PROCESS), + 'type' => env('TCP_TYPE', SWOOLE_SOCK_TCP), + 'package_max_length' => env('TCP_PACKAGE_MAX_LENGTH', 2048), + 'open_eof_check' => env('TCP_OPEN_EOF_CHECK', false), + 'package_eof' => "\r\n", + ], + 'http' => [ + 'host' => env('HTTP_HOST', '0.0.0.0'), + 'port' => env('HTTP_PORT', 80), + 'mode' => env('HTTP_MODE', SWOOLE_PROCESS), + 'type' => env('HTTP_TYPE', SWOOLE_SOCK_TCP), + ], + 'ws' => [ + // enable handle http request ? + 'enable_http' => env('WS_ENABLE_HTTP', true), + // other settings will extend the 'http' config + // you can define separately to overwrite existing settings + ], + 'crontab' => [ + 'task_count' => env('CRONTAB_TASK_COUNT', 1024), + 'task_queue' => env('CRONTAB_TASK_QUEUE', 2048), + ], + 'setting' => [ + 'worker_num' => env('WORKER_NUM', 1), + 'max_request' => env('MAX_REQUEST', 10000), + 'daemonize' => env('DAEMONIZE', 0), + 'dispatch_mode' => env('DISPATCH_MODE', 2), + 'log_file' => env('LOG_FILE', '@runtime/logs/swoole.log'), + 'task_worker_num' => env('TASK_WORKER_NUM', 1), + 'package_max_length' => env('PACKAGE_MAX_LENGTH', 2048), + 'upload_tmp_dir' => env('UPLOAD_TMP_DIR', '@runtime/uploadfiles'), + 'document_root' => env('DOCUMENT_ROOT', BASE_PATH . '/public'), + 'enable_static_handler' => env('ENABLE_STATIC_HANDLER', true), + 'open_http2_protocol' => env('OPEN_HTTP2_PROTOCOL', false), + 'ssl_cert_file' => env('SSL_CERT_FILE', ''), + 'ssl_key_file' => env('SSL_KEY_FILE', ''), + 'task_ipc_mode' => env('TASK_IPC_MODE', 1), + 'message_queue_key' => env('MESSAGE_QUEUE_KEY', 0x70001001), + 'task_tmpdir' => env('TASK_TMPDIR', '/tmp'), + ], +];