Jump to content

AJAX Chatroom, speed problems and questions


kratsg

Recommended Posts

The files with source code will be posted as soon as I can get access back on the FTP

 

I've got an AJAX Chatroom set up and working. Problems are speed mainly. For example, I have two ajax requests that are being sent, both every 3 seconds. One request gets all the messages (up to a certain point) from the database, returns html and the javascript simply puts that into the div. The second one gets the current users in the chatroom (based on the server, sorts by most recent to not most recent), returns html and the javascript puts in another div.

 

The new messages has the following variables per message:

  • Timestamp (HH:MM am/pm)
  • Optional Image in front of username
  • Username
  • message id/message number

 

Each message has this format:

 

IMG? Username: (timestamp) Message (post number)

 

The messages will be very simple, the tag that wraps the whole message will most likely be a span tag and contains the text-color and bgcolor attributes.

 

The users list has the following:

  • Timestamp (HH:MM am/pm)
  • Optional Image in front of username
  • Username

 

IMG? (link for options to contact user) Username (timestamp)

 

The link for options to contact user is to send a personal message, clicking it will change the div at the bottom to display links for different things. This is not going to be included in the output from the php file.

 

One problem is the speed, that the server is taking too long to respond. I've heard of things like using XML format in order to pass it through instead, but I'm not quite sure how the hell I would do this really. I understand that you can pass attributes through XML with nested tags and stuff, but not sure how this helps or how I would even read it?

 

I can understand that I can get the most recent message id, and send that back when checking for new messages, but I'm not sure how I can do this dynamically.

 

I am going to attempt to stick an iframe at the bottom for submitting the message, so I don't have the ajax request for posting a message. Can anyone confirm that this will work better than using an ajax request? IE:

 

<form name="blah" method="post" action="postmessage.php" target="iframe_name">

 

Instead of:

 

<form name="blah" onsubmit="run_ajax_functions();">

 

Thanks, and I don't expect this to be solved very quickly. I'm hoping to expand my script to make it a bit cleaner, and faster :-)

Link to comment
Share on other sites

  • 2 weeks later...

I'm not sure if I understood this right or not but... are you saying that every three seconds, EVERYONE in the chatroom downloads EVERYTHING in the chat room all over again?

 

If this is the case then it can be sped up dramatically by only download new messages.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.