HTML5 SERVER-SENT EVENTS allows a web page automatically update data from a Web server.
Before a website that needs updating had to file a petition to a web server. Now a web page can be updated automatically whenever there is any change in the server data, the website will receive them without having to request them.
Thus a web page is automatically updated without user intervention, without having to refresh the page, like, a listening service, which receives information from a server without having to do anything to receive it.
Example is used:
- Pages that show automatic updates on FACEBOOK and TWITTER
- Pages that display automatically updated news (RSS FEEDS)
- Pages that display sports scores automatically.
Syntax of a SERVER-SENT EVENT
They create an object-SENT EVENT SERVER, called "server", which is implemented in dynamic web page "time.php"
Example of use:
1. - First create the website will be updated automatically:
Create the page "time.htm"
Explanation of file:
We verify that your browser supports this object HTML5
We built an object-SENT SERVER called "server" will be updated with information obtained from the website "time.php"
When the output of this website "time.php" change, then there will be an event that is collected on our website "time.htm" and update the item "text", thus showing our updated information automatically.
2. - Create the file "time.php" that generates the information to update
Explanation of the previous file:
The header indicates the content type is "text / event-stream"
In the header indicates that the page is not cached
We pick the date and time the web server
We build the message with the word "data" and the message to send.
We send the message to the listener service