PHP: Check mysql database every 10 seconds for any new rows

前端 未结 5 1834
南笙
南笙 2021-01-20 17:23

I am making a php chat and am starting the php checking database part. So when a user types something into the chat, it gets recorded in the MySQL database, how would I chec

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 18:12

    Make a while for 30 seconds, and check the db every second, once you find a record the while is being broken, also it is being broken when 30 secs are expired.

    $sec = 1;
    while($sec <= 30) {
       if(has record)
          Send to the user;
       $sec++;
    
       sleep(one sec here);
    }
    

    Use sleep for 10 secs in order to check every 10 secs...

提交回复
热议问题