JAXL XMPP脚本可以工作,但永远不会停止加载

时间:2013-02-06 04:42:31

标签: php xmpp facebook-chat

我正在将Facebook Chat实施到我的网站中,所以我使用JAXL来实现XMPP。似乎该脚本发布了我想要的消息,但每当我运行它时,页面只是保持加载和加载而永远不会停止。为了回到该网站,我必须在浏览器中清除它的cookie。不确定问题是什么,我在日志中没有看到任何错误。看看代码:谢谢!

$client = new JAXL(array(
        'jid' => $user['facebookID']."@chat.facebook.com",
        'fb_app_key' => "XXXX",
        'fb_access_token' => $user['facebook_access_token'],
        'force_tls' => true,
        'auth_type' => 'X-FACEBOOK-PLATFORM',
        'log_level' => JAXL_INFO,
        'priv_dir' => "includes/lib/jaxl/tmp"
    ));

    $client->add_cb('on_auth_success', function() {
        global $client;
        _info("got on_auth_success cb, jid ".$client->full_jid->to_string());
        $client->set_status("available!", "dnd", 10);

        $msg = new XMPPMsg(array('to'=>'-XXXX@chat.facebook.com'), 'test message');
        $client->send($msg);
    });

    $client->add_cb('on_auth_failure', function($reason) {
        global $client;
        $client->send_end_stream();
        _info("got on_auth_failure cb with reason $reason");
    });

    $client->add_cb('on_chat_message', function($stanza) {
        global $client;

        // echo back incoming message stanza
        $stanza->to = $stanza->from;
        $stanza->from = $client->full_jid->to_string();
        $client->send($stanza);
    });

    $client->add_cb('on_disconnect', function() {
        _info("got on_disconnect cb");
    });

    //
    // finally start configured xmpp stream
    //
    $client->start();

    echo "done";

1 个答案:

答案 0 :(得分:1)

我已经使用本地jabber服务器测试了您的代码。

我得到了相同的结果(页面不断加载),直到我添加了“$ client-> send_end_stream();”在on_auth_success函数的末尾。

$client->add_cb('on_auth_success', function() {
    global $client;
    _info("got on_auth_success cb, jid ".$client->full_jid->to_string());
    $client->set_status("available!", "dnd", 10);

    $msg = new XMPPMsg(array('to'=>'-XXXX@chat.facebook.com'), 'test message');
    $client->send($msg);

    // Close the connection
    $client->send_end_stream();
});

似乎脚本在没有事件发生时会延迟。 之后页面超时。