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

20 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.

Shakeel | February 24, 2011 at 8:42 AM

nice work

Shakeel | March 15, 2011 at 8:28 AM

how to recieve message from gtalk by xmphp

Luis | September 30, 2011 at 8:58 PM

Is currently xmpphp able to connect with gtalk? I try the example but the execution time expires

Sanal | January 12, 2012 at 7:38 AM

Getting “Could not connect before timeout.” error.
Please help me.

Ivan Karov | January 19, 2012 at 3:03 AM

Can you please send me the “Working on a task” plugin for FogBugz. I really need that one.

Author comment by Žilvinas Šaltys | January 24, 2012 at 10:01 AM

Sorry. I don’t have it anymore. But fogbugz has an API that you can use and quickly make it yourself :)

Author comment by Žilvinas Šaltys | January 24, 2012 at 10:02 AM

Sorry, I’ve written this long ago and not sure if it works anymore or not. If you manage to find why not please let me know and I’ll update it.

Vidmantas Norkus | March 19, 2012 at 10:39 AM

after sending message php throws about 2000 warnings PHP Warning: fclose() expects parameter 1 to be resource, null given in …XMPPHP/XMLStream.php on line 403 and it takes 3 seconds to send message

Vidmantas Norkus | March 19, 2012 at 10:52 AM

commenting this line
“$this->processUntil(‘end_stream’, 5);”
in XMLStream.php helps to solve that great 5 seconds flood

jay | July 4, 2012 at 6:55 AM

How to receive chat from Gmail .
Is there is any way to achieve this.

leela | July 7, 2012 at 7:00 AM

Deprecated: Function split() is deprecated in C:\xampp\htdocs\sivra\chat\xmpphp-0.1rc2-r77\XMPPHP\XMLStream.php on line 266

Deprecated: Function split() is deprecated in C:\xampp\htdocs\sivra\chat\xmpphp-0.1rc2-r77\XMPPHP\XMLStream.php on line 266

Deprecated: Function split() is deprecated in C:\xampp\htdocs\sivra\chat\xmpphp-0.1rc2-r77\XMPPHP\XMLStream.php on line 266

Deprecated: Function split() is deprecated in C:\xampp\htdocs\sivra\chat\xmpphp-0.1rc2-r77\XMPPHP\XMLStream.php on line 266

Deprecated: Function split() is deprecated in C:\xampp\htdocs\sivra\chat\xmpphp-0.1rc2-r77\XMPPHP\XMLStream.php on line 266

Deprecated: Function split() is deprecated in C:\xampp\htdocs\sivra\chat\xmpphp-0.1rc2-r77\XMPPHP\XMLStream.php on line 266

Deprecated: Function split() is deprecated in C:\xampp\htdocs\sivra\chat\xmpphp-0.1rc2-r77\XMPPHP\XMLStream.php on line 266

leela | July 7, 2012 at 7:05 AM

how to open ssl in php using xmpp…

meghendra | January 22, 2013 at 6:11 AM

Could not connect before timeout.

i got this error please help me …

meghendra | January 22, 2013 at 6:19 AM

1358835426 [INFO]: Connecting to tcp://talk.google.com:5222 1358835426 [ERROR]: Could not connect. 1358835431 [INFO]: Connecting to tcp://talk.google.com:5222 1358835431 [ERROR]: Could not connect. 1358835436 [INFO]: Connecting to tcp://talk.google.com:5222 1358835436 [ERROR]: Could not connect. 1358835441 [INFO]: Connecting to tcp://talk.google.com:5222 1358835441 [ERROR]: Could not connect. 1358835446 [INFO]: Connecting to tcp://talk.google.com:5222 1358835446 [ERROR]: Could not connect. 1358835451 [INFO]: Connecting to tcp://talk.google.com:5222 1358835451 [ERROR]: Could not connect.

hey i got these errors now

what i do now ???

Help me

Leave a comment!

<<

>>

Find it!

Theme Design by devolux.org