I am attempting to begin a HTTP persistent connection from the Silverlight application to some PHP page (ie without developing a new TCP connection for every HTTP request) located by an Apache server.

As a result, I want the webserver to transmit its HTTP reactions using the "Connection" header set to "Keep-alive". Client-side, there does not appear to become any problem because the network API supplied by Silverlight is essentially a wrapper from the browser network capabilies, from what I have read : therefore if the browser supports HTTP 1.1 and Connection: Keep-Alive automatically because of its demands, it's fine. Content-Length can also be well defined, to ensure that the server knows when it needs to send the response. However, the server reaction to the PHP request sets methodically "Connection:" to "close", thus ending the bond and stopping a persistent connection.

I have attempted several things to operate for this problem : different Techniques (GET and Publish), clearly giving a "Connection: keep-alive" towards the response using the following PHP code at the outset of my script :

header("Connection: Keep-alive");

The second adds the expected header towards the response, that is good, but an additionnal "Connection: close" continues to be appended later within the response headers.

Could it be an element of PHP or Apache which makes sure "close" (for many security or performance purpose, I am speculating) or shall we be held just missing something here ?

Thanks ahead of time.

P.S. : By sniffing at packets, I have observed that does not some use "Keep-alive" and also the TCP connection is reestablished. Is not Keepalive the default and preferred behavior under HTTP 1.1 ?

The Keep-Alive functionality isn't intended for persistent connections.

Keep-Alive is supposed to reduce the amount of connections for any website. Rather than developing a new connection for every image/css/javascript inside a web page many demands is going to be made re-utilizing the same connection.

You will find some configurations that prevent this in Apache too, like most of demands on the connection or timeouts between demands. This can also eat your assets extremely fast because every connection needs its very own thread.

You need to change to another solution, that's made for your type of work.

For services that keep the connection open you are able to have a look at http://orbited.org and http://twistedmatrix.com/trac/

Since PHP does not manage the HTTP connection, it's not a way to alter this setting. You have to set that in servers. For instance, you are able to enable keep-alive such as this in Apache if you work with mod_php,

KeepAlive On