HTML and CSS Reference
Listing 4.9. Client code for connecting to an event stream
Try it out!
Everything is now in place for you to try the application. If you haven't already, copy all
the files to a location where your web server can access them (as discussed earlier in this
chapter, this is likely to be either /var/www/html or C:\Inetpub\WWWRoot) and have a go.
You can use a couple of different browsers to simulate multiple users and try talking to
Controlling the default server timeout
There's one thing to bear in mind if you're using PHP on Apache, as in this example: The
default script timeout is 30 seconds. This means that after 30 seconds the script on the serv-
er will be terminated and the connection will be dropped.
This isn't a problem on the client side, because it should automatically reconnect to the
event source. By default, a reconnection will be attempted every 3 seconds, but it's also
possible to control this from the event stream by emitting a retry directive:
The number is a time in milliseconds. This should force the browser to wait 10 seconds
before attempting a reconnect. Controlling the retry time would be useful if you knew the
server was going to be unavailable or under high load for a short time.