First step with php and ejabberd

Hello everyone,

its my first time working with xmpp server (its new for me and I'm trying to understand the roots)

As the first step what I want to do with the ejabberd server:

I want to create a simple "Who's online" list. How would you implement the feature
which I want to extend with chat / notification features. I want to see first how it works on the production (we have a lot of users being online at the same time) and I want to make my first real experience with ejabberd.

My toughts are:

Writing a php script which let the user login into the xmpp server, the user is online.
Every ex. 5 minutes the php script send again the request to xmpp server, that he is still online
and if there is no request, the user will be offline automatically due to inactivity.

I would implement it with the bosh feature (we have more than one server) so I could communicate
with the xmpp server via http request. I could write xml myself (as I read on the web, there is no real good xmpp client for php or you have a hint for me?) like that:

$context = stream_context_create(array(
    'http' => array(
      'method'  => 'POST',
      'header'  => "Content-type: text/xml; charset:utf-8\r\n",
      'content' => xml ...,
      'timeout' => 5,
    ),
  ));
$ret = file_get_contents('http://xmpp:9999/http-bind', false, $context);

The plan for the future:

- add ajax chat
- add ajax notification system

I would use the javascript client "strophe" for this features, but the first thing is to get the "Who's online" feature.

What do you think about my idea?

Your future implementation

edit : i think i should check the sent time before i try to reply ;) I'm a new forum user, sorry for that..

for the records, my reply may stay here..

Quote:

Your future implementation seems very similar to our current implementation, except we started with Openfire (for several reasons) but now i am trying to move to ejabberd.

But i need to tell you that for "who is online" feature, it is really an hard way to go with ejabberd, because there is no need.. ( Do you need a REAL TIME "who is online?" feature ? )

If your answer is NO, use an ajax call that runs in every 5 minutes on users browser, add two fields to your users table like "lastActionTime" and "onlineStatus" and update the values to the current timestamp for "lastActionTime" and 1 for "onlineStatus" in every ajax call for the user who runs it, also update the values in login and logout.
On the other hand, write another php script that will search for the users whose "lastActionTime" < "[current time - 10 minutes]", and set "onlineStatus" = 0 for these users.. (Making both fields INDEX can also improve performance)
On the page you need to get the online users, just query the users table for users whose "onlineStatus" = 1 ..
If you need additional performance, you may cache the results..

That become a php answer, more than an xmpp one, so let's have some talk about XMPP also;

At first, if you need XMPP functionality for users ( chat, multi-user chat, notification system, etc. ) and need them in real time, using "strophe" is a good way to go.

and for the XMPP clients, JAXL and XMPPHP seems good to me.

So, how would i implement "who is online?" feature with XMPP if i needed it REAL TIME?

I think i would open a Multi-User chat room and i would join all users to that room on every page load ( when you join a room, XMPP Server sends you the list of current occupants. ) so i would get what i want by only joining the room. I would set some hook methods in strophe that would work on presence changes (user joined, user leaved), and i would update my list according to these methods.

But to be honest, you have a long way to go. What i can suggest you is:
Create a seperate enviroment ( just apache and ejabberd. don't use your current website code )
Create a basic site for apache
Make them work. ;)
Get firefox, and also firebug extension (Many times, you'll need to see what is going on with the traffic)
Download strophe, make it work following instructions.

After you complete these steps, you'll be more than ready to choose your way to go, because you'll have information about many of the basics.Also evaluate the new features using this local website (For example, with some basic interface, you may try to implement MUC with two browsers, etc. )

For the last thing i can tell, believe me you'll enjoy dealing with it :)

Good luck ;)

Syndicate content