Search code examples
phpcallbackmqttmosquittophpmqtt

Php mosquitto mqtt client identify client onDisconnect


I am working on PHP project using mosquitto client, I need to check when some user disconnects, and identify the user.

I am using code callback function which only contains the reason for disconnect.

onDisconnect($callback) 

function so that I can handle the disconnect event.

How to link the event to the user in the database.

Thanks,


Solution

  • That callback is saying that your client was disconnected, not some other client (which is what you mean by "user" probably). You can know that another client disconnected only if

    • that client has set Last Will topic and disconnected abruptly - this will be published by the broker for you
    • that client will publish a specific graceful disconnection topic - you must provide the publishing

    In both cases, your client must be subscribed to the topic in question, of course.