1. Go to this page and download the library: Download nailfor/php-queue-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nailfor / php-queue-client example snippets
use nailfor\queue\ClientFactory;
use nailfor\queue\protocol\MQTT;
class MQTTClass
{
public function subscribe()
{
$url = '127.0.0.1:5672';
$options = [
//'username' => '',
//'password' => '',
'clientId' => 'php',
'cleanSession' => false,
'topics' => [
'topic_name' => [
//this flag clear message after reciev. Default true
//'clear' => false,
'qos' => 1, //only for MQTT
'message' => 'hello from topic',
],
'capital_name' => [
'qos' => 2, //only for MQTT
'message' => 'hello from capital',
],
],
];
$protocol = new MQTT; //default AMQP
ClientFactory::publish($url, $options, [$this, 'onError'], $protocol);
}
}
use nailfor\queue\ClientFactory;
use nailfor\queue\protocol\MQTT;
use Illuminate\Support\Facades\Log;
class MQTTClass
{
public function onMessage($packet)
{
//...
}
public function onCapitalMessage($packet)
{
//...
}
public function onError($reason) {
echo $reason->getMessage(). PHP_EOL;
exit;
}
public function subscribe()
{
$url = '127.0.0.1:5672';
$options = [
//'username' => '',
//'password' => '',
'clientId' => 'php',
'cleanSession' => false,
'topics' => [
'topic_name' => [
//this flag clear message after reciev. Default true
//'clear' => false,
'qos' => 1, //only for MQTT
'events' => [
'PUBLISH' => [$this, 'onMessage'],
],
],
'capital_name' => [
'qos' => 0, //only for MQTT
'events' => [
'PUBLISH' => [$this, 'onCapitalMessage'],
],
],
],
];
$protocol = new MQTT; //default AMQP
$logger = Log::channel('stderr'); //default null
ClientFactory::run($url, $options, [$this, 'onError'], $protocol, $logger);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.