× 警告!旧版文档已经暂停维护,请查看新版文档。点击前往新版文档

Coroutine\Socket->setProtocol

需要v4.3.2及以上版本

function Coroutine\Socket->setProtocol(array $settings) : bool

此方法可以时socket获得协议处理能力, 支持的参数与client相同

支持参数

  • open_ssl (bool)
  • open_eof_check (bool)
  • open_eof_split (bool)
  • open_length_check (bool)
  • package_eof (string)
  • package_length_type (string)
  • package_length_offset (int)
  • package_body_offset (int)
  • package_length_func (callable)
  • package_max_length (int)

例子

$socket->setProtocol([
    'open_length_check' => true,
    'package_max_length' => 1024 * 1024,
    'package_length_type' => 'N',
    'package_length_offset' => 0,
    'package_body_offset' => 4,
]);