PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Michael Feichtinger's Blog: PHP5 WebSocket Example - A Simple Chat

Note: This article was originally published at PHPDeveloper on 4 February 2011.
PHPDeveloper

Michael Feichtinger has posted a simple websocket example to his blog today. It shows the creation of a simple "web chat" application for real-time communication without the mess that can come with ajax.

The classic example for websockets is a chat. This chat example has only 200 lines of code (excl. the Websocket class), is really easy to understand and customizable.

He creates a basic "WebsocketClass" class that (in his example) connects to an IP and port. It uses JSON as the messaging format and some basic javascript to handle the clicks of the "chat" and "login" buttons. You can see an example in action here and download the source for the server.php here.