Amit Kumar
Amit Kumar

Reputation: 60

How to create a PHP chat app without continuous requests?

Possibly other questions similar to this one have been asked, but I think this would be something different to those that have been asked so far.

Can we create a chat app especially in PHP/MySQL/jQuery/Apache without continuous requests to server i.e. apache for a new messages if there are any? I don't want to use Comet or NodeJS, just want to know if it is possible to have a chat application that uses only AJAX to request Apache for new message using PHP.

By the way, if the answer is no, then what is the best way to have a perfect chat application in combination with PHP/MySQL/jQuery/Apache only? I think there must be some chat applications exist.

Upvotes: 0

Views: 1170

Answers (1)

Hailwood
Hailwood

Reputation: 92581

I am curious as to why you want to avoid all the technologies and methods developed specifically for these types of use cases but web sockets are the only other way to do it if you want to avoid comet.

Your chat application needs to connect to the server the read the incoming chat messages.

You have two choices:

Polling

This is continuously firing a new request off to the server at regular intervals to check for the messages. this is the typical AJAX style.

Web Sockets

Web sockets open one long running connection to the server. For a chat application if you are only interested in the newer browsers this is the way to go. As a bit of random information. Stack Overflow uses Web Sockets to check for any notifications.

Upvotes: 3

Related Questions