Open toan-leminh opened 8 years ago
Hi, Any chance I could see the script you're using to test? I don't see the increase in PHP 5.6.10, using this script:
<?php
$c = new Mosquitto\Client();
$c->onConnect(function() use ($c) {
$c->subscribe('#', 0);
});
$c->onMessage(function() {
static $i = 0;
$i++;
if ($i % 10 == 0) {
var_dump(memory_get_usage());
}
});
$c->connect('my.broker');
$c->loopForever();
Hi, I don't use memory_get_usage function, I checked directly on my VPS server using "top" or "ps aux --sort -rss" command and saw the increasing on memory of process. Here is my code:
<?php
$brokerInfo = array(
'ip' => 'xx.xxx.xxx.xxx',
'port' => '8888',
'keep-alive' => 30,
);
$clientSetting = array(
'id' => 'id',
'topic' => '/haco/traffic',
'qos' => 1,
'user' => 'foo',
'password' => 'foo',
);
// Create MQTT Client
$client = new Mosquitto\Client($clientSetting['id']);
// Set handler
$client->onConnect('connect');
$client->onDisconnect('disconnect');
$client->onSubscribe('subscribe');
$client->onMessage('message');
//$client->onLog('logger');
//Connect
$client->setCredentials($clientSetting["user"], $clientSetting["password"]);
$client->connect($brokerInfo["ip"], $brokerInfo["port"], $brokerInfo["keep-alive"]);
// Subscribe a topic
$client->subscribe($clientSetting["topic"], $clientSetting['qos']);
// Run
$client->loopForever();
function connect($rc, $message)
{
// Success
if ($rc == 0) {
echo "Connected \n";
} else {
echo "Connection Error[code = {$rc}]: {$message} ";
}
}
function subscribe(){
echo "Subscribed to a topic\n";
}
function unsubscribe(){
echo "Unsubscribed from a topic\n";
}
function message(){
//usleep(1000);
}
function disconnect(){
echo "Disconnected cleanly\n";
}
Hello @cid2610
I try to connect broker and send message, If i send huge package of message, and memory usage more than small package. Maybe your package increase size by while loop.
I do stress test below: