简体   繁体   English

如何在mysql数据库和php chat应用程序中更改用户可用性状态

[英]how to change user availability status in mysql database and php chat application

I have a chat application in which the user can change his availability status (online / offline / busy). 我有一个聊天应用程序,用户可以在其中更改其可用性状态(在线/离线/忙碌)。

On status_change event I want to update it to a MySQL database which can be visible to all online users. status_change事件中,我想将其更新为对所有在线用户可见的MySQL数据库。

Set field for last_activity_time with timestamp and everytime the user opens something or sends something update this field with the current timestamp 设置带有时间戳的last_activity_time字段,并且每次用户打开内容或发送内容时都使用当前时间戳更新此字段

but generally note that MySQL isn't the best way to create a chat app it's somehow exhaustive and doesn't scale 但通常要注意的是,MySQL不是创建聊天应用程序的最佳方法,它以某种方式详尽无遗且无法扩展

and from your code, 从您的代码中

Assume that user with no activity for let's say 5 minutes will be set to away and for 10 minutes will be set to offline, 假设将闲置5分钟且没有活动的用户设置为10分钟,将闲置10分钟的用户设置为离线,

If you use AJAX then set the user to update his status via AJAX, every let's say 1 minute and in this case you can easily identify offline from online users, ie users with time stamp difference more than 1.5 minutes will be considered offline. 如果您使用AJAX,然后将用户设置为通过AJAX更新其状态,则每隔1分钟说一次,在这种情况下,您可以轻松地从在线用户中识别出脱机状态,即时间戳差异超过1.5分钟的用户将被视为脱机状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM