How to save php stream_socket resource?

I have a Php application using stream_socket_client () to receive data via tcp from an internal server, but I would like to keep the connections alive or even better in the pool or something, to avoid a head on / off connection.

But I'm not a php guru, so I have no idea how to do this. And although I could probably figure it out in a few hours, my time will probably be better spent on choosing all the brains, so any advice?

+4
source share
1 answer

Setting the STREAM_CLIENT_PERSISTENT flag when creating a stream prevents connection downtime. Inside the flag, stream_socket_client() makes a call to pfsockopen() ( doc ) instead of fsockopen() ( doc ).

Constancy of communication is limited by the process of the server on which the connection was opened. When your script exits and you call it again, there can be no guarantee that the same process is processing your request - in this case, another connection will be opened. Enabling a connection in $_SESSION for sharing will not work.

+4
source

All Articles