Page 2 of 3
Re: php ajax chat room will increase server load?
Posted: Sun Jul 05, 2009 10:48 pm
by jackpf
Yeah, I just have the one table.
Well, you could just put
Code: Select all
setcookie('cookie_holding_id', null, -100);
on the main pae, which would, as I said, force the conversation to start from the beginning.
I don't bother caching anything...messages are sent so frequently in a chatroom I don't really see the point - it probably takes just as long to check all the files, check dates, modification times etc...
And the window.onunload thing not working isn't a huge deal...it just means that people don't get a "... has left the chatroom" message for people using firefox.
I could just as well check every now and again to see if the user is still online, with the stat tracking i have set up throughout my site...I just haven't had time to work on my IM; other stuff has taken priority.
Anyway, I'm just throwing ideas at you...it's best to have all the options before you start. Your choice though

Re: php ajax chat room will increase server load?
Posted: Sun Jul 05, 2009 11:03 pm
by s.dot
I've done this before and cpu usage wasn't a problem, although I never had more than 50 on at the same time. If it becomes a problem - delete messages (or archive them) after a set time period (to keep the table small) and index the table appropriately. use EXPLAIN on your queries to see what mysql is doing as queries are going to be the slow part.
Another alternative is socket connections.
Re: php ajax chat room will increase server load?
Posted: Mon Jul 06, 2009 8:38 am
by morris520
to JAB Creations
Thanks to reply. I think the idea is to read / write cache file on the server to save connections to database. There're two issues for my concerns. One, I am not sure doing that is any faster than talking to database. Though I don't know how secure it is even if we put a htaccess to block the http request.
Combing two techniques, I think it's good to first write to the cache on the server. Once writing to database or we can clean up the cache so to save a few times read / write to the database, assuming that writing to file is a lot faster. Is this possible?
Re: php ajax chat room will increase server load?
Posted: Mon Jul 06, 2009 8:41 am
by morris520
to jackpf
Thanks mate I think I've grab enough ideas before go. Will keep updating progress while doing it.
Re: php ajax chat room will increase server load?
Posted: Mon Jul 06, 2009 8:44 am
by morris520
to scottayy
Delete it is not a good way while I'm trying to keep them all in the database. So I need to work out a way to read newer message.
Facebook does give you an option to say if you want to delete message. That's the sample I think.
But this is not a big problem.
I will monitor the cpu in early stage but when more people are using the site, I become worried. Just being afraid of out of control. lol
Re: php ajax chat room will increase server load?
Posted: Mon Jul 06, 2009 6:41 pm
by JAB Creations
Morris, my idea is intended to reduce the number of connections made to MySQL, performance in any other regards is subjective and it's highly likely some of the other forum members would have recommendations on how exactly to apply the idea I mentioned and they in my opinion would be better suited for suggestions on the how this approach would be applied then I could provide currently.
scottayy, how much chat history (messages open total in the main area of the chat) would you personally recommend? Are we talking like 10, 100, 10,000KB? I think the later becomes more of an issue of usability (scrolling a pixel scrolls 600,000 pixels heh).
Morris...when nothing new is in the chat what are you doing to signal a response? In example I return HTTP 204 (and for IE/Opera 1223/0 since they don't understand 204 directly) for no content and it wastes no bandwidth.
Re: php ajax chat room will increase server load?
Posted: Mon Jul 06, 2009 10:25 pm
by jackpf
Why send a header saying you're not going to send anything? Why not just...not send anything?
Surely sending a 204 header wouldn't save any bandwidth...?
Re: php ajax chat room will increase server load?
Posted: Mon Jul 06, 2009 10:36 pm
by JAB Creations
jackpf wrote:Why send a header saying you're not going to send anything? Why not just...not send anything?
Surely sending a 204 header wouldn't save any bandwidth...?
You're kidding, right?
First and foremost headers aren't counted towards your bandwidth. Secondly no response == server timeout. There is a very clear and undebatable line between a timeout and HTTP 204 no content. If your script detects several timeouts in a row it would be advisable to have the script alert the user that they have either been disconnected from the internet or that the connection tot he server has been severed for whatever reason.
Re: php ajax chat room will increase server load?
Posted: Tue Jul 07, 2009 5:14 am
by morris520
Guys
Anyone heard about
http://xmpp.org/ and OpenFire?
Re: php ajax chat room will increase server load?
Posted: Tue Jul 07, 2009 6:35 am
by jackpf
Not in any great detail.
Are you able to install this stuff on your server though?
Re: php ajax chat room will increase server load?
Posted: Tue Jul 07, 2009 8:11 am
by morris520
To jackpf
I am doing bit reading on this and related things now. More reading I do more interests I am getting.
It actually fit various servers as I read and I will keep updating my progress about this work.
Rather than writing it from the ground, I think it's more likely will go for integration with Openfire + Sparkweb using PHP and MySQL.
Re: php ajax chat room will increase server load?
Posted: Tue Jul 07, 2009 4:14 pm
by morris520
Right come back to update my progress
After my researches I found two good examples
http://www.ajaxim.com/
And Openfire, Spark.
But it comes to me as part of my requirements as:
1 - need to use push not pull technique because we are targeting quickly-increased numbers of users
2 - Try as much as possible to avoid loading server, whch seems to be a client push client procedure
This is the real thing. I thanks for all guys replied previously but now I am getting to start coding.
Anyone got the mean idea of 'push'?
Re: php ajax chat room will increase server load?
Posted: Fri Jul 10, 2009 7:14 am
by morris520
Right
I am lost again. Just wondering how PUSH is better over PULL?
e.g. HTTP streamming is an implementation of PUSH. But it keeps outputing cotentents to the client (empty content when no new data ) and what is different from refreshing page at the client-side?
If we are saying Instant Messenger here, this technique will use quite a lot resource to output "new data", more likely, it outputs a lot of chunks.
If PUSH is better than PULL, why? I think asking for refreshing every 2 secs at the client side is no different from streamming every 2 secs from server to client?
Please correct me any professor!
Re: php ajax chat room will increase server load?
Posted: Fri Jul 10, 2009 7:44 am
by jackpf
Well, I don't know much about this, but I've just done a bit of research.
Push will likely be the most efficient, since you don't have users requesting data when there is none - connections are only made when there is data to be sent.
However, I'm unfamiliar with "push" techniques...my ajax chat is pretty much the furthest I've ever gone with ajax

Re: php ajax chat room will increase server load?
Posted: Fri Jul 10, 2009 7:58 am
by VladSun
morris520 wrote:If PUSH is better than PULL, why? I think asking for refreshing every 2 secs at the client side is no different from streamming every 2 secs from server to client?
The server won't PUSH every 2 seconds - it will PUSH only when there is new data to be sent.
Client will PULL every 2 seconds because it *doesn't know* whether there is new data or not.