Creating PHP in-time live chat

What's the best way to create live chat that will be used between the website members?

The live chat should work in-time.
LVL 12
Mohamed AbowardaSoftware EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In time for what? Do you want to roll your own for some reason?

There are plenty of pre-existing chat scripts available.
Mohamed AbowardaSoftware EngineerAuthor Commented:
I don't want chat room, I want live chat that can be used between any two members on the website.

The main thing I am looking for is "the best idea that fit what I want".

Do I need to use AJAX to frequently make request for updates? or use ob_flush which I think it will cause processes problem.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Mohamed AbowardaSoftware EngineerAuthor Commented:
@leakim971: As I mentioned, the first thing I am looking for in this question is "the best idea", I can do everything myself, I only need the best idea that will not greatly affect on the server processor.
Mohamed AbowardaSoftware EngineerAuthor Commented:
@leakim971: I must do everything myself without using third parties other than jQuery.

I would appreciate if you could post how it works without using HUGE server resources.
Currently Comet work fine with long polling (use of ob_flush)
With long polling you reduce the number of request between server and the browser

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohamed AbowardaSoftware EngineerAuthor Commented:
@leakim971: You suggest using ob_flush, however I don't want to use any third-parties, would you recommend me to use ob_flush?

If Yes, please post sample PHP code for live interaction between the server and two clients.
For example :

if you need help understand the comment, don't hesitate, I'm french
Mohamed AbowardaSoftware EngineerAuthor Commented:
@leakim971: I need to understand the idea, how it actually works in facebook?
Mohamed AbowardaSoftware EngineerAuthor Commented:
@leakim971: Do you think that making HTTP request over a persistent connection till it receive data can cause high load on the apache server if there are alot of users using the chat at the same time?

For example: In the case there are 100,000 user using that chat at the same time, I think it will create 100,000 process running at the same time since the persistent connection will keep the script running until there is data to return to the client.
Mohamed AbowardaSoftware EngineerAuthor Commented:
Another thing, when the data received from client A while client B is waiting, how to transfer the data to client B?
If I HAD to write my own module I would:

1) Create a "messages" database and table with rows, "id,sender,message
2) Create a PHP page that returns all results from that table
3) Create a PHP page to calculate the total number of records, to simply submit entries to that table if there are fewer than 100 results, or to delete all results older than the most recent 100 (defined by unique auto increment id)
4) Create an AJAX function to call the page created in step 2 every x seconds (you can adjust the interval according to your preferences).

This will take a big toll on you resources, but should be workable if you don't have a very high-traffic site.
Mohamed AbowardaSoftware EngineerAuthor Commented:
@Zupreme: What If I have very high traffic on the website?
Mohamed AbowardaSoftware EngineerAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.