protocol

Yêu cầu (workerman >= 3.2.7)

Giải thích:

string Worker::$protocol

Cài đặt lớp giao thức của instance Worker hiện tại.

Lưu ý: lớp xử lý giao thức có thể được chỉ định trực tiếp trong quá trình khởi tạo Worker khi lắng nghe các tham số. Ví dụ:

$worker = new Worker('http://0.0.0.0:8686');

Ví dụ

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

$worker = new Worker('tcp://0.0.0.0:8686');
$worker->protocol = 'Workerman\\Protocols\\Http';

$worker->onMessage = function(TcpConnection $connection, $data)
{
    var_dump($_GET, $_POST);
    $connection->send("hello");
};

// Chạy worker
Worker::runAll();

Mã ở trên tương đương với mã dưới đây

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

/**
 * Đầu tiên sẽ kiểm tra xem người dùng có lớp giao thức tùy chỉnh \Protocols\Http hay không,
 * Nếu không thì sẽ sử dụng lớp giao thức tích hợp Workerman\Protocols\Http
 */
$worker = new Worker('http://0.0.0.0:8686');

$worker->onMessage = function(TcpConnection $connection, $data)
{
    var_dump($_GET, $_POST);
    $connection->send("hello");
};

// Chạy worker
Worker::runAll();