编程语言
首页 > 编程语言> > php应用容器workerman_TcpConnection类protocol属性说明及范例

php应用容器workerman_TcpConnection类protocol属性说明及范例

作者:互联网

protocol属性说明

string Connection::$protocol

设置当前连接的协议类

protocol属性范例

use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker('tcp://0.0.0.0:8484');
$worker->onConnect = function(TcpConnection $connection)
{
    $connection->protocol = 'Workerman\\Protocols\\Http';
};
$worker->onMessage = function(TcpConnection $connection, $data)
{
    var_dump($_GET, $_POST);
    // send 时会自动调用$connection->protocol::encode(),打包数据后再发送
    $connection->send("hello");
};
// 运行worker
Worker::runAll();

标签:protocol,TcpConnection,Worker,worker,workerman,connection,Workerman
来源: https://blog.csdn.net/weixin_44039407/article/details/121956828