Home  >  Article  >  PHP Framework  >  How to multi-thread workerman

How to multi-thread workerman

(*-*)浩
(*-*)浩Original
2019-12-12 09:58:534009browse

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__ . &#39;/vendor/autoload.php&#39;;
use Workerman\Worker;
$worker = new Worker();
$worker->onWorkerStart = function(){
    $mqtt = new Workerman\Mqtt\Client(&#39;mqtt://test.mosquitto.org:1883&#39;);
    $mqtt->onConnect = function($mqtt) {
        $mqtt->subscribe(&#39;test&#39;);
    };
    $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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn