php_nub_qq Posted April 28, 2013 Share Posted April 28, 2013 Hi. Can anybody tell me how I can make the server send out data to connected users upon an event? The case is say 2 people are sending messages, chatting, instead of having ajax calls every second is there a way to tell the server when to display new messages? I believe in order for this to happen the browser has to not close the connection to the server but as my nickname states I'm not that good and I don't know how to do this hence I'm asking Quote Link to comment Share on other sites More sharing options...
trq Posted April 28, 2013 Share Posted April 28, 2013 The technology your looking for is called websockets. http alone is stateless, and there is no such thing as keeping a connection alive. I believe there are a few libraries around for php which handle this. Ive not used any though. Ratchet is the first result I found on Github. https://github.com/cboden/Ratchet Quote Link to comment Share on other sites More sharing options...
php_nub_qq Posted April 28, 2013 Author Share Posted April 28, 2013 (edited) Alrighty so in order to use websockets I need to install an extension for the server to support websockets, is this correct? Edited April 28, 2013 by php_nub_qq Quote Link to comment Share on other sites More sharing options...
php_nub_qq Posted April 28, 2013 Author Share Posted April 28, 2013 I watched a bunch of tutorials and this seems so complicated to me. I just want to ask one last thing before I dive into this because I just had an idea that doesn't seem that bad to me but of course I need to ask first. So the idea is that just like polling to send a request from the client but instead of returning the wasteful "no new data" the server goes through an infinite loop with a sleep of say 1 sec and exits the loop only if there's new data? The call from the client will be synchronous ( or asynchronous I don't really know which one lol but basically the one that can't be sent more than once until it's returned ). Is this a good option ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.