What technology to use for chat? I would like to create an open connection.
When I put a new message to the database. I want to automatically without using the timer and making loops came a new message to the browser.
I have Linux web hosting with a MySQL database.
I tried to make retrieving new messages and use the timer. Every three seconds I am using Ajax retrieve data. This solution seems to me inefficient, so looking for others.
PHP is a server-side scripting language, which means all the PHP is processed before the page even loads. In order to generate a chat-like environment, you would need to use Javascript to establish an open connection to the back-end (the PHP part). There are many methods to doing this, including polling (timers) and sockets (much more complicated).
The best way I know of to handle a chat-like service using Javascript would be to check out Node.js and its capabilities, specifically demonstrated as a chat room here: http://chat.nodejs.org/.
The problem with NodeJS and persistent connections in general is that most cheap hosting providers don’t allow you to have persistent connections open. You would need to pony up for a higher-cost dedicated server. There are, I believe, hosts that specifically allow NodeJS-type services in their environments, but I don’t know of any off the top of my head.