tags:

views:

39

answers:

2

I have a C++ backend application coded over a TCP socket, to which I connect PHP to. The problem is that the connection is closed on every refresh, change page, etc. I would like to keep the connection open for each client, doing something like $_Session does.

+2  A: 

This is not really what PHP (or the whole of web-based applications and services, for that matter) are meant for. It also means begging for resource problems before long because big PHP processes will be running simultaneously, instead of running for a quick moment on each request.

What speaks against making use of the normal session mechanisms from within your app (i.e. dealing with session ID cookies) like other clients?

I'm no expert in C++ but I'm sure that most http libraries can deal with a "cookie jar", which is essentially all you need to persist a session from within your client application.

Pekka
+2  A: 

While I don't know much about PHP, I can tell you that web browsers aren't designed to hold continuous connections. They have to reconnect every time they make a HTML request.

The HTTP standard specifies that the server will disconnect from the client after it has finished sending it it's request.

Alexander Rafferty
Wrikken
Oh, and psst: `Keep-Alive`....
Wrikken