weixin_33749131 2012-01-28 19:59 采纳率: 0%
浏览 40

XMPP和PHP流

im creating a website which uses php to connect to an XMPP server , and send a message However, im having a problem with sending/receiving messages .. Question is do i have to reconnect and send username/password everytime i make a request ( send a message ) ? how to avoid reconnecting ?

This is how i connect :

    $this->_socket = fsockopen("sever.tld", 5222, $errno, $errstr, 30);

i send messages using fwrite Like this :

    fwrite($Socket, $data);

i read messages using fread Like this :

    $response = @fread($this->_socket, 1024);
  • 写回答

2条回答 默认 最新

  • Lotus@ 2012-01-28 20:17
    关注

    The approach you're using is not going to work in the long run.

    Because a PHP instance effectively ceases to exist when it's finished sending a page back to the browser client, the connection you make to the XMPP server is closed. This means that all state (TLS session, authentication, &c) is lost.

    So yes, if you do it this way, you'd have to reconnect and re-authenticate on every page load.

    Please don't do it this way. You may use an XMPP-server-side adapter such as XMPP over BOSH, designed for this purpose, or an HTTP-server-side persistent connection via some daemon or longer-lived process which your PHP instances share.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料