-
Notifications
You must be signed in to change notification settings - Fork 146
/
test.php
44 lines (34 loc) · 851 Bytes
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$client = new Mosquitto\Client();
$client->onConnect('connect');
$client->onDisconnect('disconnect');
$client->onSubscribe('subscribe');
$client->onMessage('message');
$client->connect("localhost", 1883, 5);
$client->onLog('logger');
$client->subscribe('#', 1);
for ($i = 0; $i < 10; $i++) {
$client->loop();
}
$client->unsubscribe('#');
for ($i = 0; $i < 10; $i++) {
$client->loop();
}
function connect($r, $message) {
echo "I got code {$r} and message {$message}\n";
}
function subscribe() {
echo "Subscribed to a topic\n";
}
function unsubscribe() {
echo "Unsubscribed from a topic\n";
}
function message($message) {
printf("Got a message on topic %s with payload:\n%s\n", $message->topic, $message->payload);
}
function disconnect() {
echo "Disconnected cleanly\n";
}
function logger() {
var_dump(func_get_args());
}