skliz4rel Posted February 3, 2013 Share Posted February 3, 2013 Please I am developing a chat application. I need script to push back message from server db to client when users are chatting. I have been using pooling through ajax but it is running down my server each time multiple people connect to it. I have tried the Ape framework. But I dont understand it. It is all written in C. please some one helpp !!. I also tried socket but I am new and I thinking of browsers that dont yet support it. By the way I have gone very far in the project and dont know how to slot in socket into the codes. Quote Link to comment https://forums.phpfreaks.com/topic/273985-perform-server-push-back-to-client/ Share on other sites More sharing options...
kicken Posted February 3, 2013 Share Posted February 3, 2013 Websockets would be the best method, and you can get decent support by using a library such as Socket.IO. Otherwise you'll need to use either Long Polling, Short Polling or just page refreshing. None of them are that great when it comes to efficiency. Long Polling will tie up server threads/resources for each person connected while it waits for new data. Short polling won't tie up server threads, but creates a lot of traffic by constantly connecting, eating bandwidth and processing time. Page refreshing is basically like short polling but worse because you're regenerating the entire page rather than just passing message data. Long polling can be made more efficient if you write your own server to handle the connections rather than route them through something like Apache. Doing so properly can be a bit of a challenge though. Quote Link to comment https://forums.phpfreaks.com/topic/273985-perform-server-push-back-to-client/#findComment-1409897 Share on other sites More sharing options...
Andy123 Posted February 3, 2013 Share Posted February 3, 2013 As you said, polling is not a good way to go if you start to get a bit of traffic. Web sockets would be your best bet I believe. It is true that there is a challenge with the browser support, but wouldn't it be acceptable to give the user a message that their browser is updated if it doesn't support it? There are surely other methods of doing this, some of which kicken described, but many of them are quite challenging to implement. Reading your post, I have the impression that you don't want to go for something highly complicated. I'd say that web sockets is the way to go. People with old browsers can simply choose to upgrade or to not use the chat. Supporting old browser versions is something that is going away very fast, so I would just forget about it but make sure that you present the users with a user friendly message (feature checking). Quote Link to comment https://forums.phpfreaks.com/topic/273985-perform-server-push-back-to-client/#findComment-1409940 Share on other sites More sharing options...
Christian F. Posted February 3, 2013 Share Posted February 3, 2013 I'd probably set it up to try web sockets first, and if that wasn't available I'd fall back to short polling with AJAX. There is actually quite a bit that can be done to cut down on the resource usage that short polling creates, but it does require fairly extensive knowledge about the tools you're using. You should be able to get the chat to support at least around a hundred simultaneous users, if you tweak it properly. Without it affecting the rest of the site, too much. Quote Link to comment https://forums.phpfreaks.com/topic/273985-perform-server-push-back-to-client/#findComment-1409957 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.