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

Coroutine\Server->set

设置协议处理参数。函数原型

function Coroutine\Server->set(array $options);
  • 参数$options必须为一维的关联索引数组
  • Server::set 方法接受的配置项基本一致

必须在Server::start之前设置参数

长度协议

$serv = new  Swoole\Coroutine\Server('127.0.0.1', $port, $ssl);
$server->set([
    'open_length_check' => true,
    'package_max_length' => 1024 * 1024,
    'package_length_type' => 'N',
    'package_length_offset' => 0,
    'package_body_offset' => 4,
]);

SSL证书设置

$server->set([
    'ssl_cert_file' => dirname(__DIR__) . '/ssl/server.crt',
    'ssl_key_file' => dirname(__DIR__) . '/ssl/server.key',
]);