Gonzalo Ayuso has a new post today showing you how you can integrate websockets with a PHP application using a combination of Silex and socket.io, a javascript library specifically made to work with them.
WebSockets are great. We can start a persistent connection from our browser to our server and use this connection to send real time notifications to our users. Normally when we integrate WebSockets with an existing Web application, we need to face with one slight problem. Our Web application runs on a Web server (imagine, for example one Silex application). We can use a login form and ensure all requests are authorized (using a security layer). This problem is solved years ago. We can use Basic HTTP authentification, Digtest authentification, a session based athentification, token based authentificatio, OAuth, … The problem arrives when we add WebSocket server.
He mentions another solution - sharing an authentication mechanism between the frontend and backaned - but suggests something simpler using the bi-directional nature of websockets. To illustrate, he makes a simple Silex application and creates a basic template that makes the websocket request back to the localhost. He includes the simple code to make the socket.io server (node.js) and an example of using Express to handle the request and define the URL to call on the Silex application. He's also created a screencast showing the full process, start to finish.
Link: http://gonzalo123.com/2013/12/24/integrating-websockets-with-php-applications-silex-and-socket-io-playing-together
没有评论:
发表评论