Fatal error: Class 'Mosquitto\Client' not found

风流意气都作罢 提交于 2020-01-15 10:12:08

问题


I have been trying to publish a subscribe message using MQTT, but whenever I run my script it gives me this error:

Fatal error: Class 'Mosquitto\Client' not found in /Applications/XAMPP/xamppfiles/htdocs/Mosquitto-PHP-master/examples/pub.php on line 3

This is connection:

$client->connect("localhost", 1883, 5);

I have downloaded code from below: https://github.com/mgdm/Mosquitto-PHP

I tried to download code using pecl command but it gives me error:

No releases available for package "pecl.php.net/Mosquitto" install failed

The broker is working fine after firing the command. I got a message in new subscriber terminal - broker is working.

Can anyone let me know what mistake I made?


回答1:


Installing mosquitto is different than installing a php extension.

This is issue shoes up when mosquitto module is not loaded properly

Use the below method to install mosquitto extension ( Mosquitto-PHP )

phpize

./configure --with-mosquitto=/path/to/libmosquitto

make

make install

for loading module add "extension=mosquitto.so" in php.ini file To check loaded modules user phpinfo()

Find loaded .ini file with
php -i | grep 'php.ini'

The result will look like Configuration File (php.ini) Path => /usr/local/etc/php/5.6

Loaded Configuration File => /usr/local/etc/php/5.6/php.ini

for enabling module use "sudo php5enmod mosquitto"



来源:https://stackoverflow.com/questions/47029758/fatal-error-class-mosquitto-client-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!