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.

    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划