Forum Moderators: coopster

Message Too Old, No Replies

Anatomy of a PHP-AJAX chat application

Instant messanger design notes

         

vincevincevince

3:00 am on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For a general one-to-one chat application with the requirement that it only requires Javascript and HTML on the user's computer - what makes the best sense as a design direction for a PHP solution?

Here are my ideas:

  • Use usleep()-based loops to hold the AJAX message-check response from the server until a message is available
  • Messages you send to be shown in gray instantly (client side) and then changed to black when the AJAX response confirms acceptance
  • touch($userid) a file when a message is sent to a user, doesn't matter who it's from - checking file_exists() is much faster than a database lookup
  • Store actual messages in MySQL
  • Use cron to run a cleanup for closed conversations and old messages
  • Have the client-side application fire a message check request every X-seconds, but have a response reset that counter before hanging the response waiting for a message - in this way you stop 'disconnection syndrome'
  • distorto

    4:19 pm on Sep 13, 2007 (gmt 0)

    10+ Year Member



    great post! for me anyways...I'm building a php/ajax chat right now and I have some questions about your approach here.
    first, the usleep thing while typing a message sounds like a great idea. The way you worded this is confusing me, though. You say "Use usleep()-based loops to hold the AJAX message" - do you mean that you want to use usleep to put the system on hold until a new message is ready? it's confusing me to think of usleep "holding" a message, or maybe I don't understand usleep. after reading this, I thought a great idea would be to use usleep to keep checking back for a completed message...maybe that's what you meant anyways.

    also, I'm not sure I understand how you're using touch. I get the idea that "checking file_exists() is much faster than a database lookup" but how do we use the file? Is your point that we only use touch() when initiating the chat session? If we have already created the file, then won't file_exists() always return true regardless of whether or not a new message has been sent after the initial message?

    d40sithui

    5:54 pm on Sep 13, 2007 (gmt 0)

    10+ Year Member



    im a little confused as well. what do we need to use the touch() function at all?