开发者

i have a problem with my php ajax chat script

开发者 https://www.devze.com 2022-12-16 12:01 出处:网络
hello i have some problems with my php ajax script i\'m using PHP/mysql i have a field in my accounts table that will save the time for the last request from a user, i will use that to kick the id

hello i have some problems with my php ajax script

i'm using PHP/mysql

i have a field in my accounts table that will save the time for the last request from a user, i will use that to kick the idle user out of the chat. and i will make a php function that will delete all the rows that its time field more than the time limit, but where should i use this method is it okay to fire it every time a new request sent to my index.php ? i think that will make a huge lo开发者_JS百科ad on the server,is n't it ? do you have a better solution?

thanks


There are two viable solutions:

  • either create a small PHP script that makes this deletion in an infinite loop (and of course sleeps for a specified amount of time before doing it again), and then start it via PHP CLI,
  • or create one that makes the deletion only once, then exits, and call it from cron (if you're using a UNIXish server) or Task Scheduler (on Windows).

The second one is simpler, but its drawback is that you can't make the interval between the deletions shorter than 60 seconds.


A solution could be to fire the deletion function just once every few requests.

Using rand() you could give it a 1 in 100 (for example) change of running the function, so that about one page request in a 100 will clean up the expired data.

0

精彩评论

暂无评论...
验证码 换一张
取 消