socket and session

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm trying to connect to an application server using sockets.
Everything is fine with a small exception. I would like to store socket
in session, so that I wouldn't have to reconnect at every request.

I open socket using (PHP5):  stream_socket_client.
Then I try to: $_SESSION["socket"] = $newSocket.

With every new request the $_SESSION["socket"] is 0.

Anyone got any idea how to solve it?

Re: socket and session wrote:

Quoted text here. Click to load it

All handles are destroyed at the end of the request, and the only thing you  
can store in a session is a stale handle (to a socket or filehandle, or  
So that makes no sense, because when you unserialize that handle (by using  
it in your session on a new page) it is broken.

So you are stuck with reconnecting every request. :-(
(AFAIK: Only connections to the database can be made more permanent, but not  
by using a session, but by using another way to connect to the database.)

Erwin Moller

Site Timeline