4

I'm trying to use curl to make a persistent connection,much like websockets.. where once the connection is established the client and server just sends small text messages instead of a new http request each time..

For a websocket request, I am able to complete a handshake and recieve messages from the server (connection remains open). only issue is curl wont send anything with out the 'HTTP/1.1' header.

Everytime curl_exec is run, curl sends "GET / HTTP/1.1". Which is not needed once connection is established.

I can use curls custom request option to send my message but that would form a header like "message / HTTP/1.1".

It would be great if there was a way to eliminate that "HTTP/1.1" from the header.

I know php sockets are a better option but I'm just curious if there was a hacky way to make this happen(a websocket client maybe) using curl..

Any ideas ?

Zee M
  • 83
  • 6
  • Doesn't curl already use keep-alive by default? http://serverfault.com/questions/199434/how-do-i-make-curl-use-keepalive-from-the-command-line – Jonathan M Jun 02 '14 at 21:17
  • it does but how do I reply to a message from the server? Once connection is established.. the server doesnt understand http requests, its only looking for hybi10 encoded messages (as per hybi10 websocket specifications) .. and curl only seems to be sending http requests as mentioned in the question. – Zee M Jun 02 '14 at 21:20

1 Answers1

0

Curl was designed with http protocol in mind which is stateless (you open a connection, send a request, wait a reply and the close the connection).

However, you can use curl if you want. You would need to use CURLOPT_CONNECT_ONLY

NeDark
  • 1,212
  • 7
  • 23
  • 36