开发者

How to keep a socket alive after script finish executing

开发者 https://www.devze.com 2023-03-25 23:33 出处:网络
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

I have written a php script, which connects to facebook chat via tcp socket. My questions are:

  1. 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.

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消