jaxl / JAXL

Asynchronous, non-blocking I/O, event based PHP library for writing custom TCP/IP client and server implementations. From it's previous versions, library inherits a full blown stable support for XMPP protocol stack. In v3.0, support for HTTP protocol stack was also added.
http://jaxl.readthedocs.org/
Other
379 stars 121 forks source link

JAXL keeps running after HTTP disconnect when running using mod_php in apache2 #18

Open Harvie opened 11 years ago

Harvie commented 11 years ago

Hi! I am using JAXL to create XMPP-AJAX bridge using mod_php and apache2 (without secondary HTTP daemon based on JAXL) and i leave JAXL XMPP client running as long as possible (while apache or browser keeps connection open). But when i close connection to webserver JAXL keeps running on server (i am sure that there is no open connection to apache). I have XMPP echo working for test purposes and i've noticed that JAXL is able to echo back one single message when connection apache was closed. After handling this event (echoing message) JAXL ends just like when terminated using SIGTERM when executed from terminal. So my guess is that event machine is left polling somewhere. Is it bug or feature? If it's feature how can i avoid it? I need JAXL to stop blocking other AJAX instance right after the first is disconnected (without need to send last message to XMPP)

More closely: I want to implement AJAX form to chat with helpdesk without using any persistent daemon that can't be executed directly from apache. I need another customer to be able to chat with helpdesk once first was disconnected (without need of sending message to shut JAXL when AJAX is disconnected).

Even more closely: I am using two mechanisms: 1.) XMPP2AJAX: JAXL XMPP connection that echoes received messages to HTTP (AJAX streaming comet design) 2.) AJAX2XMPP: PHP script forwarding messages to JAXLPipe whis calss JAXL XMPP send()

Both JAXL and JAXLPipe are long-running in same process streaming to AJAX while sending messages from ajax is second oneshot script that just writes to pipe which is read by JAXL process.

Hope it's clear. THX for JAXL and THX for help :-)

abhinavsingh commented 11 years ago

@Harvie Sorry about not getting back on this earlier.

It's not a feature, yes this happens with the example http_bind.php script because they don't really send out anything back to the browser. In PHP, there is no way for the underlying script to detect if browser has closed the connection until the script is sending out something back to the browser.

In future some more work will be put up on the sample scripts. Currently HTTP Bosh related examples are there just for a start. Does that answer what you were looking for?

Harvie commented 11 years ago

@abhinavsingh THX for reply... Actually it does not matter for me how it will be implemented, but i really like to see some examples of how to implement queued chat with helpdesk where helpdesk sits on native jabber client and client sits on ajax gateway (where jabber connection is initiated ad hoc and no process is running after disconnection).

I'd also like to implement something like chat on facebook on my forum. we already have PMs, but i want them to be transparently interconnected with jabber account and therefore accesible from different sites. This is almost similar to virtual helpdesk, except every user will have his own account (and will be able to chat with more than one buddy)

And i don't think i want to mess with BOSH or similar stuff... i hate it. i had javascript solution that connected directly to BOSH server, but it sux for two reasons: 1.) was VERY CPU intensive 2.) can't have chat in more than single window (i want to use ajax so the chat popups will be synchronized between all windows = received messages will popup in all browser tabs and you will be able to respond in any of them you will choose)

That's why i want to use PHP to connect directly to TCP server and relay messages between different instances of ajax. I hope you will make some documentation to make clear how should i implement such things :-)

pmuralikrishna111 commented 11 years ago

I can suggest one thing.. Check whether it works..

Mainly you want Queued chat.. One person sitting to help(Representative)... in other side clients are on browser and chatting with the representative.

1) Representative is connected.{JAXL instance is running.} 2) When the 1st is client connected he will send some message and both can chat. right? 3) Now before closing the Client browser run a Javascript or anything script and send a message to Representative (JAXL Instance). 4) And as soon as the JAXL Instance receives some message from client browser like 'closed the connection'. then take the next client waiting in the Queue and continue chat with them...

Hope it helps something...

On Sat, Nov 3, 2012 at 2:16 AM, Tomas Mudrunka notifications@github.comwrote:

@abhinavsingh https://github.com/abhinavsingh THX for reply... Actually it does not matter for me how it will be implemented, but i really like to see some examples of how to implement queued chat with helpdesk where helpdesk sits on native jabber client and client sits on ajax gateway (where jabber connection is initiated ad hoc and no process is running after disconnection).

I'd also like to implement something like chat on facebook on my forum. we already have PMs, but i want them to be transparently interconnected with jabber account and therefore accesible from different sites. This is almost similar to virtual helpdesk, except every user will have his own account (and will be able to chat with more than one buddy)

And i don't think i want to mess with BOSH or similar stuff... i hate it. i had javascript solution that connected directly to BOSH server, but it sux for two reasons: 1.) was VERY CPU intensive 2.) can't have chat in more than single window (i want to use ajax so the chat popups will be synchronized between all windows = received messages will popup in all browser tabs and you will be able to respond in any of them you will choose)

That's why i want to use PHP to connect directly to TCP server and relay messages between different instances of ajax. I hope you will make some documentation to make clear how should i implement such things :-)

— Reply to this email directly or view it on GitHubhttps://github.com/abhinavsingh/JAXL/issues/18#issuecomment-10029710.

pmuralikrishna111@gmail.com pmuralikrishna111@gmail.com

Harvie commented 11 years ago

Well... this is quite problematic... that's exactly what i don't want to do as browser might crash or whatever... If user will pull power cord from his computer which will result in closing connection without goodbye message it will freeze the queue. and i guess there's no possibility to implement some portable time-out mechanism (eg.: without POSIX alarm())

pmuralikrishna111 commented 11 years ago

Well yah that is the problem.. "With out goodbye message and it freeze the queue."

Then Try this....

Check the Browser is in Connected state.. "AJAX", will write to a file or write in db or do whatever you can, when AJAX failed to request{When no matter return in the file or db or anything} then drop the connection...

or else

In the server side check everytime browser is alive.[this doesn't possible directly]... If every client has a JID, then check whether its alive.

On Sun, Nov 4, 2012 at 5:18 AM, Tomas Mudrunka notifications@github.comwrote:

Well... this is quite problematic... that's exactly what i don't want to do as browser might crash or whatever... If user will pull power cord from his computer which will result in closing connection without goodbye message it will freeze the queue. and i guess there's no possibility to implement some portable time-out mechanism (eg.: without POSIX alarm())

— Reply to this email directly or view it on GitHubhttps://github.com/abhinavsingh/JAXL/issues/18#issuecomment-10045668.

pmuralikrishna111@gmail.com pmuralikrishna111@gmail.com