How to keep a socket alive after script finish executing
I have written a php script, which connects to facebook chat via tcp socket. My questions are:
How to keep the socket alive even when the php script is end开发者_运维百科ed? I want other php file to communicate with facebook XMPP server via this socket? I have tried to save the socket as a session variable, but it did not work.
I tried to use pfsockopen instead of socket_create, according to some forum discussion. But I always receive failure when I call pfsockopen function.
Any one has idea how to solve this?
Thanks!
You need a standalone daemon for this.
You cannot share the socket between different PHP scripts. What @seriyPS suggests makes sense - create a PHP script, that:
- never ends
- opens socket to FB chat
- Listen on another socket
Then your PHP scripts can open socket to that 'daemon' PHP script, send a message, the daemon sends it to FB and returns the FB response.
精彩评论