Skip to content

Commit

Permalink
Return MID from publish()
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdm committed Oct 4, 2013
1 parent 3f14d46 commit d2e7c41
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/pub.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

while (true) {
$client->loop();
$client->publish('/hello', "Hello from PHP at " . date('Y-m-d H:i:s'), 1, 0);
$mid = $client->publish('/hello', "Hello from PHP at " . date('Y-m-d H:i:s'), 1, 0);
echo "Sent message ID: {$mid}\n";
$client->loop();

sleep(2);
Expand All @@ -28,7 +29,7 @@ function subscribe() {
}

function message($message) {
printf("Got a message on topic %s with payload:\n%s\n\n", $message->topic, $message->payload);
printf("Got a message ID %d on topic %s with payload:\n%s\n\n", $message->mid, $message->topic, $message->payload);
}

function disconnect() {
Expand Down
2 changes: 2 additions & 0 deletions mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ PHP_METHOD(Mosquitto_Client, publish)
retval = mosquitto_publish(object->client, &mid, topic, payload_len, (void *) payload, qos, retain);

php_mosquitto_handle_errno(retval, errno);

RETURN_LONG(mid);
}
/* }}} */

Expand Down

0 comments on commit d2e7c41

Please sign in to comment.