protocol
說(shuō)明:
string Connection::$protocol
設(shè)置當(dāng)前連接的協(xié)議類(lèi)
范例
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 時(shí)會(huì)自動(dòng)調(diào)用$connection->protocol::encode(),打包數(shù)據(jù)后再發(fā)送
$connection->send("hello");
};
// 運(yùn)行worker
Worker::runAll();