I am building a simple ajax chat client for a school project and have thought of a way to implement this, but it seems IMO to be very cumbersome approach:
1) User A sends message which is accepted by a server-side PHP script and saved to database
2) The browser of User B periodically launches a server side PHP script to check if there are any messages in the database for User B. PHP script finds messages from User A and returns them.
Is this the right approach? Can communication between these two users be achieved without a database?
(This is my first web-application…if I was making this without browsers + HTTP, I would just make a Java program with persistent class that listened on TCP sockets, and forwarded messages to the appropriate address)
Yes your solution is good enough for starting. What you are doing is polling the server if there are any chat messages for a particular user. Good enough.
But if you wanna goto the next level, (probably could be tough), you can have a server which can push new messages onto client browsers. This is called “Comet”. But it will need extensive server resources (if your userbase is going to exceed to thousands).
Try your method first and go for this next.