Optionally enable keepalive on the socket

Keepalive actively checks that the other end of the connection is still open, and prevents blocking forever on half-open connections.

I didn't enabled this by default because there are a few cases where it can cause the connection to be claused prematurely; e.g. if the other side doesn't support keepalive, or if a router drops keepalive packets.

An exception is thrown if PHP doesn't have support for enabling keepalive (if the user asked for keepalive to be enabled).