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

6 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

Author comment by Ž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.

svnlabs | March 23, 2010 at 4:14 PM

WoW!!
Very good article.. great experience with XMPP

Thanks
SV

Widyo Harsono | June 13, 2010 at 4:15 PM

i ve got lot of this error messege when trying sending IM to gtalk using XMPPHP, but i think theres no hosting problem. can everybody tell me what is this and help me how to avoid it printed to screen? thx

Deprecated: Function split() is deprecated in C:\wamp\www\XMPPHP\XMLStream.php on line 266
Deprecated: Function split() is deprecated in C:\wamp\www\XMPPHP\Roster.php on line 121

Warning: fclose() expects parameter 1 to be resource, null given in C:\wamp\www\XMPPHP\XMLStream.php on line 403

Author comment by Žilvinas Šaltys | June 13, 2010 at 4:28 PM

The deprecated warning is probably due to php 5.3. The library might be outdated by now. You could fix it by using another function such as explode. The other fclose warning I have no idea. You would have to debug it yourself.

Leave a comment!

<<

>>

Find it!

Theme Design by devolux.org