Greetings to you, dear professionals.
I have a couple of questions.
- Header keep-alive ... When the browser sends a request via ajax, the server (apache) does not close the connection for 5 seconds. So, the connection during this time is considered open, and why then when you re-send the browser again forms the headers and stuff? What is the difference? The fact is that if the browser and server do not close the connection for 5 seconds, then why bother with long-polling? What then is the difference between these two queries? In addition to the fact that with a long-polling result will come faster.
- In the previous question I mentioned long-polling, although I don’t really know how it works. Example: I have a chat and messages that are stored in the database, that is, the browser sends a request to the server, where the request itself to the database (to check for new messages) is placed in an infinite loop, and if new data is available, then the server responds . I correctly understood the principle? And if the server will not fall from such an "Infinite" number of queries to the database, well, suppose I send a cycle to sleep every 500 milliseconds, but nonetheless. How ideally should this work?
- Sockets work on the same principle (I mean checking new data), as I described in the second question?
- How long the maximum can last (in time) an AJAX request (version HTTP / 1.1). Well, for example, if you set sleep on the server for 20 minutes. Is it generally normal for so long not to close connections? Does each browser behave differently? I tried the Google Chrome version 38, the connection lasts more than 10 minutes, but I have not tried it for longer.
UPD: Buggy editor here!