API Extension: Connection support
| Project: | XMPP Framework |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | darren.ferguson |
| Status: | closed |
This patch is not complete yet, so it is just submitted for feedback and discussion.
It adds connection support to the XMPP Framework so we can have persistent connections at least during the same page request. The current api creates and destroys a connection for each operation which is not very practical nor performance wise.
Features:
- Allows connection with either server (admin) credentials, with 'get_server_connection' or with user credentials, with 'get_user_connection($account)'
- Fully backwards compatible, all methods can be passed an existing connection or not, in which case it will be created
- Also allows multiple connections during the same page request, with different credentials, as the 'server_connection' method admits full parameters.
- It doesn't really require that the underlying API supports connections. I.e. for the xmpp_xmlrpc implementation it just passes around the server credentials, so it should work the same
Usage example
<?php
$conn = xmppframework_get_server_connection();
xmppframework_send_message('me@example.com', 'chat', 'Hi there', NULL, $conn);
xmppframework_send_message('me@example.com', 'chat', 'How are you?', NULL, $conn);
xmppframework_release_connection($conn);
?>There are other small unrelated features, like an _xmppframework_api_invoke() helper function that could be reused for all the module, making the code much shorter.
The connection parameter has not been added for all the operations yet, only to the ones I'm currently using, that's why I mean the patch is incomplete yet.. I'm working with this version and seems to work fine though.
I'm also doing some experiments with persistent sockets. Passing 'persistent' => TRUE to the xmpp_api_get_server_connection() should result on that, they seem to work though one new persistent connection is recreated every time. Anyway, the jid looks as connected in between calls...
| Attachment | Size |
|---|---|
| xmpp_connection_extension.patch | 20.71 KB |

#1
Jose,
I like the approach and yes your correct it definitely makes sense to have the same connection open during the whole request rather than continually opening and closing the request.
The main issue is to make sure any connection that should be done via the user is done that way we do not cause conflict with the admin account doing something that the user cannot undo on their own account.
I like the approach, if you need anything from me on this let me know and i will assist.
#2
Agreed. But for this it doesn't help too much that the underlying api functions make assumptions about whether to use the current user for the connection. This should be a higher level option IMHO.
So this is my second try for an api rework. Main points:
Also there are some cross dependencies between the APIs and the xmppclient module. Ideally I would try to handle the users xmpp accounts (jid, password) in the xmppframework itself, or in a different module. The current patch has some improvements about this (having xmppclient dependencies handled only in xmppframework), but it still relies on xmpp api for the user-related functions.
(xmppframework, xmpp_api, xmpp_xmlrpc fully patched, not updated the other modules though)
#3
How's this doing? ;)
#4
subscribing.. performance is a considerable issue.
#5
Applied this patch and upgraded the portions in the patch in order to match the new structure for the xmppframework.
CVS commit http://drupal.org/cvs?commit=199682 is the commit for this patch.
#6