mgdm / Mosquitto-PHP

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

add PHP 8 compatibility #123

Closed nismoryco closed 2 years ago

nismoryco commented 2 years ago

This adds compatibility with PHP 8. Arguments have been updated for type hinting. Null arguments have been added to eliminate warnings on startup. The Mosquitto Message class has been updated for Zend objects and Zend strings in the property handler functions. I am not seeing any issues at the moment. However, my testing has been limited. This is my first time with PHP internals, and I am certainly not an expert.

alesinicio commented 2 years ago

Great news! I have been making some tests with PHP 8.0.8, and I cannot get it to work properly receiving messages. Specifically, if you try to access the Message object on the onMessage callback, the PHP-FPM process dies with a SIGSEGV. If you DON'T access the object, everything is fine (but worthless, of course).

Code

    $mqtt = new \Mosquitto\Client('myclientID');
    $mqtt->onMessage(function(\Mosquitto\Message $message) {
            print_r($message); //DIES WITH SIGSEGV
    });
    $mqtt->connect('172.29.192.61', 1883, 10);
    $mqtt->subscribe('#', 0);
    $mqtt->loopForever();

Publishing seems fine overall.

No expertise on internals here, but willing to help in any way possible.

mgdm commented 2 years ago

Hi! Thank you so much for your work on this. I've not had a lot of bandwidth to have a look at doing this myself recently, but I'll make time over the weekend to have a look and try to merge it. I can try and track down that segfault too.

Thanks again!

nismoryco commented 2 years ago

@alesinicio : Did you build from source with my patches? Your example is working for me.

alesinicio commented 2 years ago

Absolutely my bad -- my Dockerfile was outdated. Things seem to be working fine. I'll make extensive tests over the weekend. Great job!

UPDATE All tests work absolutely fine with PHP 8.0.8 running on a Docker container (Alpine 3.13 with nginx). Also fine on WSL-Ubuntu-18.04 with Apache. Thoroughly tested (for my use case, of course) running over PHP-FPM and PHP-CLI. Have a bunch of processes running steady for over 12 hours, publishing and receiving messages perfectly.