Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdm committed Jan 28, 2016
1 parent f945559 commit 1896453
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,29 @@ Then add `extension=mosquitto.so` to your `php.ini`.
The `--with-mosquitto` argument is optional, and only required if your
libmosquitto install cannot be found.

## Documentation
## General operation

The underlying library is based on callbacks and asynchronous operation. As such, you have to call the `loop()` method of the `Client` frequently to permit the library to handle the messages in its queues. Also, you should use the callback functions to ensure that you only attempt to publish after the client has connected, etc. For example, here is how you would correctly publish a QoS=2 message:

```php
<?php

$c = new Mosquitto\Client;
$c->onConnect(function() use ($c) {
$c->publish('mgdm/test', 'Hello', 2);
});

$c->connect('test.mosquitto.org');

for ($i = 0; $i < 100; $i++) {
// Loop around to permit the library to do its work
$c->loop(1);
}

echo "Finished\n";
```

## API Documentation

The classes in this extension are namespaced.

Expand Down

0 comments on commit 1896453

Please sign in to comment.