AJAX Instant Messenger Part 1
(Work In Progress)
AJAX Instant Messenger tutorial adds to the AJAX Web Chat tutorial to create a site-wide instant messaging service.  This tutorial is considerably more advanced than the AJAX Web Chat due to the many complex PHP and database access requirements.  If you are looking for a quick start to AJAX programming, I suggest you start with the AJAX Web Chat tutorial.

Architecture Overview
Unlike the simple AJAX Web Chat example, this tutorial will require many additional pieces in order for just the basic functionality to work.  From a general overview, we will need:
  • An Instant Message Window (Based off the AJAX Web Chat example)
  • A Login Page
  • An IM checker component
  • A current users component
  • A send IM component
How this will work is we will have an Instant Message checker component that checks the server in the background every 10 seconds to see if anyone has sent us an Instant Message.  If there are any pending IM chat requests, then we will pop-up a new Instant Message chat window for the new Instant Message chat Request.

Once we have established the chat, then the IM chat window will behave much like the AJAX Web Chat example.

We will also code a component that we can use to check the current online users and send them an IM chat request.

The Database
In the AJAX Web Chat Tutorial we put together a pretty simple database that consisted of two tables.  One for messages and one to hold the current chat sessions.  We didn't even use the chat sessions table in the AJAX Web Chat tutorial since we only had functionality for one chat area.  In part 2 (not yet published) we created a simple users table so that we could allow users to enter the chat room with a custom user name. 

In the AJAX Instant Message tutorial, we will make use of the chat sessions table and even add some additional tables so that we can identify when we have a chat request pending.  Our IM checker component will periodically check an invite table to see if anyone is wanting to chat with us.

The database will need to know the list of currently active users as well.  In order to do this, we will set a last active field to the current time on every page request or sent chat message for each user.  If the user's last active time is less than 4 minutes, then we will consider them online.