I’m trying to get my online status using XMPPHP and I can’t seem to get anything that has my status from the $conn
. Here is a snippet of my code:
require_once('XMPPHP/XMPP.php');
$conn = new XMPPHP_XMPP('talk.google.com', 5222, '[email protected]', 'xxxxx', 'xmpphp', 'gmail.com', $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
$conn->connect();
$conn->processUntil('session_start');
$conn->presence($status='Controller available.');
var_dump($conn); // this gives me a long output but nothing about status. ex: http://pastebin.com/yfs1V5Jb
I also tried getRoster()
to see a list of my friend’s info (although I’m only interested in mine) but no luck.
Any suggestions how I can get this to work? Thanks.
I've been grappling with this issue for the last 2 days, and finally figured out a hack to get things to work. I'm documenting it here, because this was the stack overflow question that appeared most often for me while searching for answers.
The $conn->presence() method not only sends your presence info to the server; it also collects presence info for every contact from the server. The fundamental problem is that when you send the $conn->presence() command, you have to give the script time to receive and process this information from the server. The example scripts all use $conn->processUntil('presence') to do this, but for some reason for me that didn't pause things long enough to get all the roster information.
To get around this, I finally just used $conn->processTime(2), forcing things to wait 2 seconds before proceeding. This is good enough for my purposes, but is clearly a hack. So using your code as an example:
To answer your question more specifically, you could use the following in place of the code under "now see the results":
That will display the online status for the jid you provide.
Note that in this example I also changed the constructor to display the most verbose log possible. This was key to helping me work through this.
A better solution would obviously be to add a $conn->processUntil('roster') command to the framework, or something like that. But since the framework hasn't been updated in 5 years, that's unlikely to happen.
Hopefully this will save someone the hours I lost trying to solve it. Cheers.