From 28a544e17f9a1c136e6bcda52196f09427b262ac Mon Sep 17 00:00:00 2001 From: blobt Date: Fri, 21 Aug 2020 15:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E8=8A=82=E4=B8=8D?= =?UTF-8?q?=E5=A4=9F=E6=97=B6=E5=80=99=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/client.php | 5 ++++- src/Pack.php | 13 +++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/client.php b/examples/client.php index 89dd3ed..56e90fa 100644 --- a/examples/client.php +++ b/examples/client.php @@ -46,7 +46,10 @@ function remoteCall(string $host, $port, string $data) { } -$ret = remoteCall("127.0.0.1", "5188", '{"controller":"site","methor":"test","params":{"id":1,"status":0}}'); +$ret = remoteCall("127.0.0.1", "5188", '{"controller":"site","methor":"test","params":{"id":1}}'); + +//'{"controller":"site","methor":"test","params":{"id":"111"}} +//'{"controller":"site","methor":"test","params":{"id":1,"status":0}}' echo "{$ret}\n"; ?> diff --git a/src/Pack.php b/src/Pack.php index 616a9be..bd67136 100644 --- a/src/Pack.php +++ b/src/Pack.php @@ -139,12 +139,13 @@ class Pack { * @return string | boolean */ public function unpack(string $pack) { - $ret = unpack($this->makeFormat(true), $pack); - - if ($ret['type'] == self::DATA_TYPE_SAMPLE_DATA - && $ret['length'] == strlen($ret['data']) - && (int) $ret['length'] <= self::$packageMaxLength) { - return $ret; + try { + $ret = unpack($this->makeFormat(true), $pack); + if ($ret['type'] === self::DATA_TYPE_SAMPLE_DATA && $ret['length'] == strlen($ret['data']) && (int) $ret['length'] <= self::$packageMaxLength) { + return $ret; + } + } catch (\Exception $e) { + return false; } return false; }