Home > Article > PHP Framework > How to multi-thread workerman
Workerman has a MT multi-threaded version that relies on the pthreads extension, but because the pthreads extension is not stable enough, this Workerman multi-threaded version is no longer maintained. (Recommended learning: Workerman Tutorial )
## workerman \ MQTT is a Workerman -based asynchronous MQTT client library that can be used to receive or send the MQTT protocol. Support QoS 0, QoS 1, QoS 2. Supports MQTT3.1 and 3.1.1 versions.
Installation
composer require workerman/mqtt
Example
subscribe.php
<?php require __DIR__ . '/vendor/autoload.php'; use Workerman\Worker; $worker = new Worker(); $worker->onWorkerStart = function(){ $mqtt = new Workerman\Mqtt\Client('mqtt://test.mosquitto.org:1883'); $mqtt->onConnect = function($mqtt) { $mqtt->subscribe('test'); }; $mqtt->onMessage = function($topic, $content){ var_dump($topic, $content); }; $mqtt->connect(); }; Worker::runAll();
The above is the detailed content of How to multi-thread workerman. For more information, please follow other related articles on the PHP Chinese website!