问题
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 withphp -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