transport
Description:
string Worker::$transport
Sets the transport layer protocol used by the current Worker instance. Currently, only three types are supported (tcp, udp, ssl). If not set, it defaults to tcp.
Note: ssl requires Workerman version >= 3.3.7
Example 1
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('text://0.0.0.0:8484');
// Using udp protocol
$worker->transport = 'udp';
$worker->onMessage = function(TcpConnection $connection, $data)
{
$connection->send('Hello');
};
// Run worker
Worker::runAll();
Example 2
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
// It is best to use an issued certificate
$context = array(
'ssl' => array(
'local_cert' => '/etc/nginx/conf.d/ssl/server.pem', // It can also be a crt file
'local_pk' => '/etc/nginx/conf.d/ssl/server.key',
)
);
// Here, the websocket protocol is set
$worker = new Worker('websocket://0.0.0.0:4431', $context);
// Set transport to enable ssl, websocket+ssl is wss
$worker->transport = 'ssl';
$worker->onMessage = function(TcpConnection $con, $msg) {
$con->send('ok');
};
Worker::runAll();