Question

Trying to write a chat, like on facebook, I wondered if two clients can connect to the same PHP-document, or, if 1 PHP-document could communicate with 2 clients at the same time?
(I just took PHP as an example, I don't mind using another server-side scripting language, although PHP is the only serverside scripting language I can program in).
With communicating I mean receiving input AND send output, via AJAX or something like HTML5 SSE.
Is this possible?
How is this called (for googling)?

Thanks.

Was it helpful?

Solution

There are hundreds of tutorials on the web that can explain how to use some technologies you're very familiar with to create a chat system (PHP, Javascript and MySQL):

http://www.tutorialized.com/tutorials/PHP/Chat-Systems/1

I recommend reading at least one of them so you can understand where each piece fits in the puzzle.

Happy coding and best of luck.

OTHER TIPS

You should look into Websockets. There's a library SocketIO which makes it real easy to do live, "realtime" communication between client and server. The server can push the chat messages to the clients.

You also should consider using Node.JS on the server, which has nice support for SocketIO.

You could make a site which automatically reloads content with AJAX, and you have to make one PHP file, which shows all messages and one which receives messages from the input form. The data you should save in a MySQL-Database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top