Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xmpphp persistent connection? #122

Open
GoogleCodeExporter opened this issue Mar 16, 2015 · 3 comments
Open

xmpphp persistent connection? #122

GoogleCodeExporter opened this issue Mar 16, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

/*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
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant