[GRLUG] XMPP Proxy/Middleware Service?

Ben DeMott ben.demott at gmail.com
Wed May 27 23:52:47 EDT 2009


Ahh - a stateful server daemon to maintain a stateful session on behalf of a
non-stateful client - and herein lies the problem.

Sounds like a job for one of the Jabber c libraries - I'm sure google
accomplishes this through Python (which gmail is written in) or a compiled
language.

Here's some code to get you started ... (borrowed from apache)

for ( ; ; ) {
  // your session code
}

Although I don't agree PHP is a wasteland - PHP as an SAPI (which is what
you are referring to) wasn't designed to have it's execution piped to
waiting or stateless threads from user requests through DMA unfortunately -
However the PHP thread is capable of leaving open 'persistant' connections

pfsockopen();

I'm not an expert on the XMPP / Jabber protocols but  I've implemented other
persistent connections (such as terminal emulation) across requests using
persistent sockets... I have to guess that's how xmpphp is implemented (it
would hopefully not suffer the log out, log in) issues you are describing
across requests.
You've actually spiked my curiousity so I'm going to look into the protocol
more, as implementing a decent chat client is something I've always wanted
to do but just haven't really had a need.

A completely different approach is to open a PHP thread for each jabber
login request received - then ignore user abort, and have the thread query a
database on a regular basis to determine if the connection should be closed
based on timeout / user abort.
The never ending thread would persist for each user, and it may be smart to
set the maximum memory size to something pretty small so if there are
hundreds of simultaneous users PHP doesn't reserve all the systems memory
across all of the possible threads.
You might even be able to consolidate ALL users to one never ending thread
on the server and just conditionally open and close as many different
sockets as needed based on queries to a database.

Yet another and probably more elegant solution is to perform interprocess
communication to a persistent php thread using sockets and the
socket_create_pair() function.

So when PHP get's namespaces and lambda functions in 6.0 will it be promoted
to an oasis? Oh I can't wait to be Y combinating in my wasteland.

The real issue is that almost all PHP opensource applications have the goal
of reaching the largest audience - with that goal comes the requirement to
run on shared hosts, and with that comes the lack of applications that
interact with or are concerned with persistent services such as XMPP; thus
the wasteland.

But I digress...

On Wed, May 27, 2009 at 5:06 PM, Ben Rousch <brousch at gmail.com> wrote:

> I have done some (very) small experiments on something similar to what
> you're asking for. I did not really look for any sort of robust middleware.
>
> I used the Jive/OpenFire/Ignite Realtime (Whatever their name is these
> days) Smack Java library to create a xmpp client/bot. A user would chat with
> my xmpp bot, and the bot would process their commands and store the results
> in a database. I then used LAMP and AJAX to poll the database and post on a
> web site.
>
> _______________________________________________
> grlug mailing list
> grlug at grlug.org
> http://shinobu.grlug.org/cgi-bin/mailman/listinfo/grlug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shinobu.grlug.org/pipermail/grlug/attachments/20090527/086f903f/attachment.htm 


More information about the grlug mailing list