Skip to content
ghedipunk edited this page Mar 8, 2012 · 1 revision

PHP WebSockets is intended for the PHP developer who has access to configure their server (or who can request such configuration changes).

WebSockets is a technology that was originally part of the HTML5 standard, but is now being developed separately. It is designed to overcome specific limitations of AJAX by creating an open TCP socket for bi-directional communication between a server and scripts on a web page. Namely, it greatly reduces the overhead associated with creating and tearing down connections for normal HTTP content, and allows the server to send information to a script on the page without the script first polling the server, reducing latency and keeping bandwidth consumption down.

This PHP WebSockets server is designed from an object-oriented perspective. It is expected that the user will extend the base abstract class WebSocketServer and override the connected(), closed(), and process() methods, at a minimum.

The real meat of the server comes from the process() method, where the data from the client is sent after the protocol specific details have been taken care of. Most user interactions will end up here, so this is the place to put your application logic.

The other two abstract methods which must be overridden are connected() and closed(). connected() happens after the connection has been fully created and the client is ready to send and receive. This method is available to allow your application to deal with the new user, such as by storing information about them in your database, sending initial messages, doing further authentication beyond ensuring they're coming from the right domain, etc. 'closed()', on the other hand, happens after the connection is fully closed, and is intended more to give you an opportunity to clean up.

Clone this wiki locally