View Full Version : Looking for working examples php/perl to connect XMPP server openfire
hr61369256
07-04-2008, 04:06 PM
Hi,
I have a lot of beginners questions, sorry. I was googling in the internet very long time without any satisfying result.
1. Is there any working example with PHP connecting to an xmpp server (in my case openfire)? All the rare examples I found didn't work. (I tried PHP first, because the communication should be started out of a web page).
2. Because I like Perl more than PHP, I searched for this possibility too. But there I've got the problem that I found no package net::xmpp for Windows out there.
So I think, all I need for the beginning is a short hint to good experiences or a well working example, for growing up. Thank you very much in advance.
Ralf
Jehan
07-04-2008, 04:33 PM
You want this from scratch? Or you intend to use some XMPP library? Because if you use an xmpp library, you probably have a "connect" function to do this all for you.
For a "from scratch version" in php, you can have a look at my wordpress plugin:
http://wordpress.org/extend/plugins/jabber-feed/
But doing the same thing must be pretty the same in perl, just replacing php functions with perl equivalent.
Just look the "log" method of the xmpp_stream class (file "xmpp_stream.php"). As you will see, it is divided in 4 steps: connect (basic socket connection), authenticate (login/password exchange), bind (get a resource) and session_establish (begin a new session) which are the basic steps as described in RFC 3920 and 3921. So of course to understand this all, reads these RFC.
My code is licensed GPL3, so as long as you license also in GPL3, you can use it (or simply get inspiration from it, if you are not licensing in GPL3). Anyway there can probably be better code. I am working on a new project on the side (will be also GPL3, but it won't be PHP, nor perl), and I will use a really better design.
hr61369256
07-05-2008, 12:22 PM
Thank you very much for your answer.
To your questions:
I'm looking for an easy way to work with xmpp functionality. This could be with the help of a library or starting from scratch. What I want to do is the following:
during an project which is spread over the world people writes information (logging records) into an MySQL database. These records (inserted via php web form) should be send instantly (same moment when they are written into the database) to other people via xmpp (subscribed in one xmpp server). The record writer selects the xmpp-accounts via select list.
I think, because of this php web form it could be easier to use a php solution.
I have tried to read the pages you gave via url to me. I think I'm not deep enough in this stuff (RFC 3920 and 3921, I will go in this ...) to get the message. But it sounds slightly similar to my problem I described above?
Jehan
07-05-2008, 02:09 PM
Hello,
yes there are two ways to do what you intend to do:
1/ Either you keep on the client side a list of all the recipient and then you send the same message for all of them.
2/ Either you use the "PubSub" (Publish Subscribe) service which enables some account to publish on a XMPP "node", and people to subscribe to this node. So the client only send once the message to this node and does not care about the list of recipient people. On its side the server deals itself with forwarding this message to all people subscribed to the node.
The second method is exactly what my php plugin does. I think that's a better method. But unfortunately this is rather a proof of concept because very few Jabber servers have the pubsub feature implemented without big bugs (I mean so big that it is a useless implementation), and very few clients have this feature at all (knowing what to do when receiving a pubsub message).
As for the server part fortunately it should be fixed soon (I have made some bug reports for ejabberd and apparently a developper has begun to work on them; and I have been told that Tigase should a full and good pubsub implementation. Maybe will I have some chance to test it soon). For the client part I don't know. I think I know one workaround for this by accompanying the pubsub message by some normal-message version so that the clients may just display the notification as any normal message (which MAY be what you want... but may not too). But I still have to test it against the current server's and client's implementations anyway.
Jehan
vBulletin® v3.8.0 Release Candidate 2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.