简体   繁体   中英

How to automatically send new record to mysql row every minute in php

i am currently programming my own social network (temal.cf). Users can register, login and chat with other users. If user 1 logs in, the row "last_login" will update to the current time and the row "status" will change to "online" in the phpmyadmin database. If user 1 logs out it will set the row "status" to "offline". So if a user is just closing his browser or is closing the tab, he will just stay as online. Thats a problem. My idea to solve this now is to update every 1 or 2 minutes the row "last_login" in the database. If user 1 closes his browser, it wont send updates to the database anymore. And if a different user checks the online status of user 1, it will check if the difference between the current time and between the time than user 1 logged last in is more than like 2-3 minutes, if yes, it should say that user 1 is offline, if not,it should say user 1 is online.

So how can I automatically send a new record to the sql phpmyadmin database every minute in php language?

(I know my english is verby bad, sorry:/)

this is not passible just with PHP you have to use some kind of frontend solution with backend solution

few solutions are:

  1. Socket.io
  2. sending AJAX, every min with setInterval... ( terrible idea, but it will work in some cases ), then checking with CRON script time dif...
  3. every time you do any backednd activity just update your DB time, also terrible idea for perfomance..., also if u have db engine like MyISAM or any other they have specific rules how DB works, for example MyISAM will LOCK whole table when updating single row... so all other requests have to wait
  4. endless AJAX ( wrost idea ), and when u get status code 499 then u know what happends... but if u do this then there is something wrong...
  5. ....

there is a lot of solutions but most of them are just TERRIBLE and your BOSS will not be happy:D, best is Socet.io for your case, or just do 2 and send it every 10 min and its OKEY if your app have some delay in ONLINE status...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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