SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP/Ajax Chat Problem--I'm Stumped

    I'm in the midst of creating a full-blown Ajax/PHP chat system with user pictures, chat "bubbles" and a "who's online" component. It's been working pretty well during a few months of testing.

    Recently, though, I've had a few signs of flakiness in this system. Namely, for reasons that are unclear to me, every so often a user's chat window will not get updated with the most recent line of chat. The chat IS getting in the database just fine, but not always getting sent back to every user's window.

    Without divulging too much code (yet), I wonder what could be causing this? I'm stumped. Here is some pertinent information:

    1. This script is basically made up of 2 PHP pages; a "user interface" page where users send and see chat and who's online, and a "function" page which actually handles all the inserting into and selecting from the MySQL databases.

    2. I'm using XML as the storage/structural engine for displaying the chat. I've been hearing about JSON recently. Is it really faster? Could XML be slowing things down?

    3. The user interface page sends the xhttprequest to send and receive every four seconds. Would slowing it down help matters?

    These are just some preliminary thoughts that spring to mind. I'm happy to show the code if need be, but I thought I'd lay this out first.

    I'd be so grateful for any ideas from the wonderful SitePoint community. I've learned so much from all of you already!

    Cheers...

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using just one request every four seconds? What about when the user presses enter once he types a message?

    Reason I ask is because with httprequests, there's no guarantee when you're going to get the response, which can lead to:

    - javascript sends xhrequest "A" to get the updated chat
    - user types something and hits enter, causing xhrequest "B" to be sent
    - due to network problems, xhrequest "A" gets bogged down
    - xhrequest "B" returns and some updated chat gets displayed
    - xhrequest "A" finally returns and overwrites request "B"s update

    Without seeing any code/trying it out it's hard to say what's going on really, but that is one thing that can happen.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •