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; }