Search code examples
ajaxweb-applicationsclient-servercometmulti-user

Client-client interaction design issue?


Okay, here is my situation: I'm looking for the best design approach. I'm working in PHP/Smarty on the server-side and HTML/jQuery for the client-side, but that is not really important here.

I have this multi-user system on my server. It is a kind of ordering system. A standard user -- let's call them customer -- can order some items from the webshop. The webshop contains items from multiple sellers.

When the user (customer) places the order, the seller -- also a user in the system -- has to get notified that there is a new order and confirm/decline it.

When the seller confirms/declines the order, a notification has to be send to the user giving him/her the status of his/her order.

Orders are stored in the database, as well as order confirmations.

The only way I can think of right now is to constantly -- in short intervals with AJAX -- check for new records in the database, from the sellers' screen, and do the same thing for the customer when he/she is waiting for the confirmation.

But I'm thinking, is there any way to trigger notifications to the seller when the user(customer) places the order so the seller could load the database only when needed and not constantly in intervals?

The same goes for the customer when he/she is waiting for confirmation. But that is not so important because it doesn't happen all the time. There is a waiting limit when the order will be automatically declined if the seller doesn't respond.

I hope you understand my question.


Solution

  • The answer to a similar question here on Using Comet with PHP suggests that there could be some problems with Apache threads being tied up from all the open connections to the client.

    According to this blog post on PHP Continuations, it is possible to use continuations with PHP, but there just doesn't seem to be as much documentation on the subject. However, CometChat did it in PHP. It's not clear if they are using continuations, but they claim to scale to 100,000 connections. More information on PHP Comet can be found in this similar Stack Overflow Question regarding A Solution for Comet and PHP.

    I was also going to suggest using Java, as Java has a really great track record for implementing scalable Comet with Continuations. Conversion Support is an example of chat software that uses comet and continuations on a Jetty Web Server.

    Since your code is in PHP, you could Use Querces to run your PHP code on the JVM. Additionally, Querces PHP Benchmarks Suggest it's Faster than Apache, which gives you added advantages. Check out the Querces Project for more information.

    UPDATE: I suggest you do your own benchmarks or research the speed issue yourself, as there may be some information that may suggest Apache is faster. If using Querces, it's important to understand that you would essentially be writing Java that just happens to look and feel like PHP. Thus, I'd suggest additional research there as well so that you understand the advantages and disadvantages of this approach.