目录
当前位置: 首页 > 文档资料 > WorkerMan 3.x 手册 >

属性 - protocol

优质
小牛编辑
129浏览
2023-12-01

说明:

  1. string Connection::$protocol

设置当前连接的协议类

范例

  1. use WorkermanWorker;
  2. require_once __DIR__ . '/Workerman/Autoloader.php';
  3. $worker = new Worker('tcp://0.0.0.0:8484');
  4. $worker->onConnect = function($connection)
  5. {
  6. $connection->protocol = 'Workerman\Protocols\Http';
  7. };
  8. $worker->onMessage = function($connection, $data)
  9. {
  10. var_dump($_GET, $_POST);
  11. // send 时会自动调用$connection->protocol::encode(),打包数据后再发送
  12. $connection->send("hello");
  13. };
  14. // 运行worker
  15. Worker::runAll();