Check if user closed the page in PHP?

前端 未结 9 2004
孤城傲影
孤城傲影 2020-12-22 06:04

I made a chat using PHP and JavaScript chat and there is a disconnect button which removes user from the chat removing him from user list first. But if the user closes brows

9条回答
  •  无人及你
    2020-12-22 07:06

    You answered your own question: if you don't detect a request for new messages from a user over a given length of time (more than a few seconds), then they left the room.

    The nature of HTTP dictates that you need to do some AJAX type of communication. If you don't want to listen for the "give me more messages" request (not sure why you wouldn't want to), then build in a heartbeat type communication.

提交回复
热议问题