Download the PHP package gutink/swoole_co_mqtt without Composer
On this page you can find all versions of the php package gutink/swoole_co_mqtt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gutink/swoole_co_mqtt
More information about gutink/swoole_co_mqtt
Files in gutink/swoole_co_mqtt
Package swoole_co_mqtt
Short Description swoole coroutine mqtt client. fork try-to/swoole_mqtt
License MIT
Informations about the package swoole_co_mqtt
MQTT
Coroutines MQTT client for PHP based on swoole.
Installation
composer require gutink/swoole_co_mqtt
文档
Example
subscribe.php
Run with command
publish.php
Run with command
API
- Client::__construct()
- Client::connect()
- Client::reconnect()
- Client::publish()
- Client::subscribe()
- Client::unsubscribe()
- Client::disconnect()
- Client::close()
- callback onConnect
- callback onMessage
- callback onError
- callback onClose
__construct (string $host, int $port, [array $options])
$host
Service address.-
$port
port. $options
is the client connection options. Defaults:keepalive
:50
seconds, set to0
to disableclient_id
: client id, defaultswoole-mqtt-client-{$mt_rand}
protocol_name
:'MQTT'
or 'MQIsdp
'protocol_level
:'MQTT'
is4
and 'MQIsdp
' is3
clean_session
:true
, set to false to receive QoS 1 and 2 messages while offlinereconnect_period
:1
second, interval between two reconnectionsconnect_timeout
:30
senconds, time to wait before a CONNACK is receivedusername
: the username required by your broker, if anypassword
: the password required by your broker, if anywill
: a message that will sent by the broker automatically when the client disconnect badly. The format is:topic
: the topic to publishcontent
: the message to publishqos
: the QoSretain
: the retain flag
resubscribe
: if connection is broken and reconnects, subscribed topics are automatically subscribed again (defaulttrue
)bindto
default '', used to specify the IP address that PHP will use to access the networkssl
defaultfalse
, it can be settrue
orssl context
see http://php.net/manual/en/context.ssl.phpdebug
defaultfalse
, settrue
to show debug info
connect()
Connect service __construct($host, $port, $options)
.
reconnect()
Reconnect service __construct($host, $port, $options)
.
publish(String $topic, String $content, [array $options], [callable $callback])
Publish a message to a topic
$topic
is the topic to publish to,String
$message
is the message to publish,String
$options
is the options to publish with, including:qos
QoS level,Number
, default0
retain
retain flag,Boolean
, defaultfalse
dup
mark as duplicate flag,Boolean
, defaultfalse
$callback
-function (\Exception $exception)
, fired when the QoS handling completes, or at the next tick if QoS 0. No error occurs then$exception
will be null.
subscribe(mixed $topic, [array $options], [callable $callback])
Subscribe to a topic or topics
$topic
is aString
topic or anArray
which has as keys the topic name and as value the QoS likearray('test1'=> 0, 'test2'=> 1)
to subscribe.$options
is the options to subscribe with, including:qos
qos subscription level, default 0
$callback
-function (\Exception $exception, array $granted)
callback fired on suback where:exception
a subscription error or an error that occurs when client is disconnectinggranted
is an array ofarray('topic' => 'qos', 'topic' => 'qos')
where:topic
is a subscribed to topicqos
is the granted qos level on it
unsubscribe(mixed $topic, [callable $callback])
Unsubscribe from a topic or topics
$topic
is aString
topic or an array of topics to unsubscribe from$callback
-function (\Exception $e)
, fired on unsuback. No error occurs then$exception
will be null..
disconnect()
Send DISCONNECT package to broker and close the client.
close()
Close the client without DISCONNECT package.
callback onConnect(Client $mqtt)
Emitted on successful connection (CONNACK
package received).
callback onMessage(String $topic, String $content, Client $mqtt)
function (topic, message, packet) {}
Emitted when the client receives a publish packet
$topic
topic of the received packet$content
payload of the received packet$mqtt
Client instance.
callback onError(\Exception $exception)
Emitted when something wrong for example the client cannot connect broker.
callback onClose()
Emitted when connection closed.
material
https://github.com/walkor/mqtt https://github.com/try-to/swoole_mqtt
All versions of swoole_co_mqtt with dependencies
ext-swoole Version >=4.4