javascript - PHP freezes on sleep() -
I was voting for a chat script for a long time. I have designed it to work like this:
- Customer sends a request for server (php)
- The server is requested, and a loop (For 1 minute)
- On every iteration in the loop, the server checks the 'new' messages from the database
- If there is a new message, the new message The server with the list dies. (I used the die string function
- That response is received by the customer, and is processed.
- If there is no new message for 1 minute , The other dead () function looks like a
code with a 'message' status:
& lt ;? php while ($ time) & Lt; 60) {If (new message) (die (new message)} So (1); $ Time ++;} die (no new message);
During 60 seconds (when this is any new message I'm unable to open a new page, nor are other users able to access any page (using xampp). How do I fix this problem? I know that this approach can not be so great, but I would like to know this problem, and how to solve it, rather it is suggesting how to do it in any other way (Web sockets, etc.)
Comments
Post a Comment