happy9335 / jaxl

Automatically exported from code.google.com/p/jaxl
GNU General Public License v3.0
0 stars 0 forks source link

Handle multiple jabber (xmpp) connections inside 1 php process #24

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I don't use env/jaxl.php, but created own controller which connects to xmpp, 
and has getXML in loop.

In some cases I need to have 2 JAXL class instances and have 2 open streams 
(with different accounts). 
Example: I create new user with admin account using XEP-0133, but to store 
vCard I need to connect as newly created user.

But, JAXLPlugin contains static methods/variables, and this leads to: when 
stanza arrives from one stream, handlers from both JAXL instances are invoked 
by JAXLPlugin.

I propose to change JAXLPlugin to bind hooks basing on pid. (or other unique 
key)  
You can find code, maybe it will help.

By the way, there was a bug in JAXLPlugin::remove ($callback can not be used as 
array index).

Original issue reported on code.google.com by a.bas...@gmail.com on 21 Oct 2010 at 3:00

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by mailsfor...@gmail.com on 21 Oct 2010 at 5:48

GoogleCodeExporter commented 8 years ago
Hi Bastun,

Packaged Jaxl library don't force any controller model by itself. 
"env/jaxl.php" is most common way to go for developers building SINGLE JAXL 
instance applications, however not for MULTI JAXL instance applications. 
Depending upon your application you will have to use a combination of 
"env/jaxl.php", "env/jaxl.conf" and "env/jaxl.ini" to build a controller for 
your use case.

Previously, I used MULTI JAXL instance for building a Bosh Connection Manager 
(BCM based on XEP-0124), where BCM internally used to keep a map of issued Bosh 
sid and corresponding Jaxl instance reference to make sure correct XMPP account 
is used whenever required. Can your application keep such a mapping to 
automatically detect correct Jaxl instance for usage when required?

I didn't run into JAXLPlugin invoking registered hooks for all connected Jaxl 
instances because JAXLPlugin also pass back $jaxl instance variable as 
parameter to called back method in your application code. Hence in your 
application you always know from which $jaxl instance this callback was 
generated. Can this be used in your application code to distinguish between 
connected XMPP accounts?

$jaxl->jid itself is a unique key to distinguish between two connected streams 
inside MULTI JAXL instance applications. Even if you have connected same XMPP 
account twice (same bare Jid), $jaxl->jid will still be unique because resource 
part is always something like jaxl.123456789

I looked at the patch you have attached:
1) Indeed sendXML($xml, $force=false) seems a better approach.
2) JAXLPlugin::remove needs some overhauling for sure, will test it out.

Rest of the patch can be avoided if the approach discussed above can be helpful 
for your application, otherwise we will surely fix this out in the core itself. 
Kindly let me know how it goes and if you want to have a look at BCM code 
sample for help. Do let me know if you can share your code so that I can help 
you out directly with that. Also would love to see controller approach you have 
used for your application.

Original comment by mailsfor...@gmail.com on 22 Oct 2010 at 8:46

GoogleCodeExporter commented 8 years ago
Hi Bastun,

In a multi-instance jaxl application i noticed cron job registration per jaxl 
instance will help. Your patch seems be backward compatible too for $pid=0.

I will merge this patch into Jaxl dev branch, not only for JAXLPlugin but also 
for other core classes which still don't differentiate between multiple jaxl 
instance.

Original comment by mailsfor...@gmail.com on 24 Dec 2010 at 5:54

GoogleCodeExporter commented 8 years ago
Hi Bastun,

I have modified your patch a little and pushed it to Jaxl dev master branch at 
github. Summary of changes made inside JAXLPlugin class can be found here: 
https://github.com/abhinavsingh/JAXL/blob/693eb605912affb257208f3b2d2e6111522067
a4/core/jaxl.plugin.php

Now applications and core files make use of $jaxl->addPlugin($hook, $callback, 
$priority). However, old style JAXLPlugin::add($hook, $callback, $priority, 
$jaxl->uid) still holds good.

If 4th parameter to JAXLPlugin::add() is not passed, callback is treated as 
global i.e. called for all running Jaxl instances.

Kindly let me know if you can test it out with your application and verify the 
changes. Also do let me know if you made any interesting patches for multiple 
jaxl instance applications.

Original comment by mailsfor...@gmail.com on 27 Dec 2010 at 10:19