GoslingAllenLee / xmpphp

Automatically exported from code.google.com/p/xmpphp
0 stars 0 forks source link

xmpphp persistent connection? #122

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi:
  I have several questions I hope can be resolved?
    1.How to do a persistent connection?
    2.How to obtain the roster and get his state?
  Thanks!

Original issue reported on code.google.com by comfi...@gmail.com on 25 May 2012 at 7:37

GoogleCodeExporter commented 8 years ago
/*Hi, this code will give to two things:
1. Your roster information.
2. Your Online friends.
separated by '~~~' sign.
*/

<?php
require_once("XMPP/XMPP.php");

function get_online_presence(){

    $user_name = 'xxxxxxxxxx';
    $password = 'xxxxxxxxxxxxxxx';
    $end_loop = 0;

    $conn = new XMPPHP_XMPP('talk.google.com', 5222, $user_name,$password, "xmpphp", 'gmail.com', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);
    $conn->autoSubscribe(); 

    try {
        $conn->connect();
        while($end_loop <=0) {
            $payloads = $conn->processUntil(array('end_stream', 'session_start','roster_received'));
            foreach($payloads as $event) {
                $pl = $event[1];
                switch($event[0]) {

                    case 'session_start':
                        $conn->getRoster();
                        $conn->presence('');
                    break;

                    case 'roster_received':
                    $array_contact=$pl;

                    foreach($array_contact as $user => $friends_name){
                        echo "<li>".$user.'_NAME_'.$friends_name['name'].'</li>';
                    }
                    $end_loop++;
                    break;
                }
            }       
        }
        echo "~~~";
        set_time_limit(2);
        while(1)
        {
            $payloads = $conn->processUntil(array('presence'));
            echo "<li>".$payloads[0][1]['from']."_Show_". $payloads[0][1]['show']."</li>";
        }

    $conn->disconnect();

    } catch(XMPPHP_Exception $e) {
        die($e->getMessage());
    }

}

Original comment by jay.vinf...@gmail.com on 10 Jul 2012 at 9:45

GoogleCodeExporter commented 8 years ago
Hello, 
I am new to xmpp and I don't know much more about xmpp. Can anyone please tell 
me that is 'presence' event is already defined in the xmpp or we need to add 
handler for that??

Original comment by MayurS.n...@gmail.com on 6 Aug 2013 at 10:03

GoogleCodeExporter commented 8 years ago
when i try with above code its throw 

Fatal error: Maximum execution time of 30 seconds exceeded in 
E:\xampp\htdocs\wb\xmpphp\XMPPHP\XMLStream.php on line 383

if i increase MAX Execution time than process continuously running without any 
result.

Please Help if you have any idea.

Thanks
Vijay Lathiya

Original comment by lathiyav...@gmail.com on 10 Aug 2013 at 5:46