mgdm / Mosquitto-PHP

A wrapper for the Eclipse Mosquitto™ MQTT client library for PHP.
BSD 3-Clause "New" or "Revised" License
531 stars 146 forks source link

loop/loopFoever throw empty exception randomly #63

Open ChaojieZhang opened 7 years ago

ChaojieZhang commented 7 years ago

I am writing a client to save all chat to MySQL, but loop/loopForever not working correctly.
CODE: $c = new Mosquitto\Client('saveAllChat',1); $c->onConnect(function() use ($c) { $c->subscribe('#', 1); }); $c->onMessage(function($m) { // var_dump($m); }); $c->connect('127.0.0.1'); for ($i = 0; $i < 1000; $i++) { echo $i.' '; $c->loop(1); //the loop throw excption randomly, sometimes $i = 10, sometimes $i = 543 } ERROR: `PHP Fatal error: Uncaught exception 'Mosquitto\Exception' in /home/cj/www/dev/mqtt/onMeesage.php:18 Stack trace:

0 /home/cj/www/dev/mqtt/onMeesage.php(18): Mosquitto\Client->loop(1)

1 {main}

thrown in /home/cj/www/dev/mqtt/onMeesage.php on line 18

Server environment: Ubuntu 14.04 LTS libmosquitto-dev installed from ppa:mosquitto-dev/mosquitto-ppa the extention was intalled by 'pecl install Mosquitto-alpha'

anyone have any idea?

msedv commented 7 years ago

Absolutely the same here: after some seconds the loop:

for ($i = 0; $i < 10000; $i++) { // Loop around to permit the library to do its work $c->loop (100000); usleep (10); print $i . " "; } ends with the above exception ("Uncaught exception 'Mosquitto\Exception'"), no matter if calling loop without parameter, with 0, 1 or anything above. Same behaviour if using loopForever instead of making my own loop,

PHP Version 5.6.29. The Extension was installed with pecl install Mosquitto-Beta.

Anyone any ideas?

mgdm commented 7 years ago

can you try again with the latest released version? I've not yet managed to reproduce this.