Home > PHP Framework > Workerman > body text

How to multi-thread workerman

(*-*)浩
Release: 2019-12-12 09:58:53
Original
4081 people have browsed it

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
Copy after login

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template