The Developer Day | Staying Curious

Apr/09

7

Google Talk XMPP Jabber integration with PHP

Internaly GoogleTalk uses XMPP messaging protocol. XMPP - The Extensible Messaging and Presence Protocol. Often also called as Jabber. Since it’s an open protocol means it’s possible to develop your own clients to connect to other XMPP servers.

There are quite a few xmpp libraries that provide client functionality. The one I tried myself is XMPPHP. It’s usage is really simple. For example to send a message you would do something like this:

require_once('XMPPHP/XMPP.php');

$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'user@gmail.com',
'password', 'xmpphp', 'gmail.com', $printlog = false,
$loglevel = XMPPHP_Log::LEVEL_INFO);

try {
    $conn->connect();
    $conn->processUntil('session_start');
    $conn->presence();
    $conn->message('friend@gmail.com', 'Hi!');
    $conn->disconnect();
} catch(XMPPHP_Exception $e) {
    die($e->getMessage());
}

I find this to be quite valuable. Who these days does not keep their IM live all the time? I imagine it’s like a cellphone. Meaning you can use it for many different services.

For example I developed a small application that checks if every one of my collegues is “Working on a task” in FogBugz and if not it sends an automated message to them to remind them that they should select a task they are working on. I also have a small tracker that tracks a local torrents network looking for high rated IMDB movies. I have an idea that it would be nice to integrate my tracker with GTalk so that it would inform me when a new episode of House MD is available or a new highly rated movie appears. The sky is the limit ;)

RSS Feed

3 Comments for Google Talk XMPP Jabber integration with PHP

Balan | January 17, 2010 at 6:47 AM

I am getting “Could not connect before timeout.” error

Balan | January 17, 2010 at 6:49 AM

Any hosting problem? Please help me

Žilvinas Šaltys | February 12, 2010 at 12:09 PM

I’ve tested it myself and it seems to be working properly. It could be a hosting problem. Try running it on your own server or somewhere else.

Leave a comment!

«

»