Skip to content

open_length_check 开启下,自动拼拆业务包  #31

@shenzhe

Description

@shenzhe
Member

现状


open_length_check是目前最常用的解决业务粘包的方式,

现在实际开发过程中大都会做如下事情:
send:
$client->send(pack($config['package_length_type'], strlen($sendData)).$sendData);

recv:
$recvData = $client->recv();
//省略了一些异常判断
return substr($recvData, $this->config['package_body_offset']);

问题


收发包操作频繁,一方面增加理解难度,另一方面也会带来一些性能损耗

改进


底层在内置pack和unpack方法
$client->send(package_pack($sendData));
$recvData = package_unpack($client->recv);

选项


Activity

changed the title [-]RFC-1011 open_length_check 开启下,自动拼拆业务包 [/-] [+]open_length_check 开启下,自动拼拆业务包 [/+] on Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @shenzhe

        Issue actions

          open_length_check 开启下,自动拼拆业务包 · Issue #31 · swoole/rfc