Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 5, 2009, 03:36   #1
Mike4x4s
SitePoint Guru
 
Join Date: Sep 2007
Posts: 841
Reloading certain data

I have a chatroom and a custom made chatroom list that displays chatrooms and next to the name the amount of users currently in the room, it pulls this information from a mysql database. I was wondering is it possible to reload just the amount of users in the chatroom only when the data is changed. I was thinking of automatically refreshing it every 10 seconds but that would take alot of server load. I would like to do this dynamically.

thanks.
Mike4x4s is offline   Reply With Quote
Old Nov 5, 2009, 04:03   #2
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 454
Yes.
Modern chats are all based on AJAX technic, which don't reload page at all, but sends requests to the server and recieves data.
It's all written in javascript though.
And it sends requests every, say 10 sec too.
Shrapnel_N5 is online now   Reply With Quote
Old Nov 5, 2009, 04:06   #3
Mike4x4s
SitePoint Guru
 
Join Date: Sep 2007
Posts: 841
wouldnt requests every 10 seconds slow down my server by far if i have like 300 users connected and all trying to receive data?
Mike4x4s is offline   Reply With Quote
Old Nov 5, 2009, 04:11   #4
AnthonySterling
Previously, SilverBulletUK.
 
AnthonySterling's Avatar
 
Join Date: Apr 2008
Location: North-East, UK.
Posts: 2,917
Much less so than a full page refresh for 300 users every 10 seconds.
AnthonySterling is offline   Reply With Quote
Old Nov 5, 2009, 04:12   #5
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 454
No, it wouldn't. Common server can handle thousands of requests.
Room's population is't that critical, so, it can be refreshed every 1 min
Shrapnel_N5 is online now   Reply With Quote
Old Nov 5, 2009, 04:17   #6
AnthonySterling
Previously, SilverBulletUK.
 
AnthonySterling's Avatar
 
Join Date: Apr 2008
Location: North-East, UK.
Posts: 2,917
Personally, I think 10 seconds is way too long for a chat application, never mind a minute.

A large delay is hardly conducive to having a conversation, hence the popularity of Instant Messenger applications.

Make this element configurable in your application, you maybe pleasantly surprised.
AnthonySterling is offline   Reply With Quote
Old Nov 5, 2009, 04:38   #7
Mike4x4s
SitePoint Guru
 
Join Date: Sep 2007
Posts: 841
can someone please supply me with a base ajax code?
Mike4x4s is offline   Reply With Quote
Old Nov 5, 2009, 04:53   #8
AnthonySterling
Previously, SilverBulletUK.
 
AnthonySterling's Avatar
 
Join Date: Apr 2008
Location: North-East, UK.
Posts: 2,917
If you're using a JS framework, many provide an example. Check out jQuery or MooTools et al.
AnthonySterling is offline   Reply With Quote
Old Nov 6, 2009, 01:42   #9
PHPycho
SitePoint Guru
 
PHPycho's Avatar
 
Join Date: Dec 2005
Posts: 637
A very good go for ajax click here
PHPycho is online now   Reply With Quote
Old Nov 6, 2009, 15:30   #10
joebert
Floridiot
 
joebert's Avatar
 
Join Date: Mar 2004
Location: Clearwater, FL
Posts: 676
If you seriously anticipate that many users being connected at one time you need to abandon the idea of a browser based chat and look into a real application for chat.

There is a lot of overhead with HTTP compared to something designed to have numerous constantly connected systems waiting for responses from a central server and occasionally sending messages.

If you are determined to stay in the browser, at least look at using Java (as in the compiled applets, *.jar files, not javascript or *.js files) or Flash. At least they can be setup to conenct to a socket server and listen constantly.
joebert is online now   Reply With Quote
Old Nov 8, 2009, 20:40   #11
Sven S.
SitePoint Enthusiast
 
Sven S.'s Avatar
 
Join Date: May 2005
Location: Hamburg, Germany
Posts: 53
As joebert said: Browser-based chat just sucks, sorry.
Sven S. is offline   Reply With Quote
Old Nov 8, 2009, 22:32   #12
frank1
SitePoint Guru
 
frank1's Avatar
 
Join Date: Oct 2005
Posts: 975
what i do is
make a function
and use ajax to call it every x second appending random number to called url....
works and simple

and one step further u can add cache feature as well...which will improve performance....
frank1 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 01:57.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved