Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Websockets in Your Synchronous Site
Feb 26, 2016 @ 11:03:53

The SitePoint PHP blog has a new tutorial from Christopher Pitt showing you how to integrate websockets into your application for asynchronous, real-time functionality. His method makes use of a service called Socketize (with a free tier available).

Asynchronous architecture is common in other programming languages, but it’s only just finding its feet in PHP. The trouble is that this new architecture comes with a cost.

I don’t talk about that cost enough. [...] When I recommend frameworks like Icicle, ReactPHP, and AMPHP, the obvious place to start with them is to create something new. [...] It takes a lot of work to integrate new, asynchronous features into existing applications. Often there are good reasons and great benefits, but a rewrite is always a hard-sell. [...] I’m going to show you a Sockets-as-a-Service service, called Socketize.

He walks you through the setup of the code and account to create a simple CRUD (create, read, update, delete) system for a deck of cards. He starts with a simple synchronous API spitting back JSON of the card data. Then he creates the frontend client (simple Javascript) to fetch the data and append the values to the page. Next comes the asynchronous handling - he shows the creation of the Socketize account, setting up a new application (with keys) and making use of the SocketizeJavascript client to create the websocket and hook it all together.

tagged: websockets asynchronous socketize application frontend service thirdparty

Link: http://www.sitepoint.com/websockets-in-your-synchronous-site/

Gonzalo Ayuso:
POST Request logger using websockets
Nov 17, 2015 @ 10:25:32

In this post to his site Gonzalo Ayuso shows you how to create a logger for your POST requests and their information with a bit of helpful code and Websockets.

Last days I’ve been working with background geolocation with an ionic application. There’s a cool plugin to do that. [...] Basically this plugin performs a POST request to the server with the GPS data. [...] I can develop a simple Silex application with a POST route and log the request in a file or flush those request to the console. This’d have been easy but as far as I’m a big fan of WebSockets (yes I must admit that I want to use WebSockets everywhere :) I had one idea in my mind.

He shows the creation of a simple Silex-based application with just two endpoints (channel that handles both GET and POST) that uses the Guzzle HTTP library to listen on the Websockets port for incoming connections. He then shows how to add the code necessary on the frontend (using express) to send the POST data automatically to the waiting Silex application. He's provided the full working code for the example on his GitHub account as well so you can see it fully fleshed out.

tagged: websockets post log silex tutorial example gps plugin automatic debug

Link: http://gonzalo123.com/2015/11/16/post-request-logger-using-websockets/

PHPBuilder.com:
Creating Real Time Applications with PHP and WebSockets
Jul 29, 2014 @ 12:13:07

On PHPBuilder.com today there's a new tutorial introducing you to the combination of PHP and WebSockets to make real-time requests to fetch data in your application.

This article will explore the main PHP libraries used to create real time, bi-directional applications between clients and servers over WebSockets. WebSocket is full-duplex client/server communication over TCP. It is also a new feature available in browsers as a part of the HTML5 specs that allows JavaScript clients to open bi-directional socket connections to a server. [...] WebSocket connections are basically TCP socket connections that following the WebSocket rules to communicate. The WebSocket Protocol is an independent TCP-based protocol.

They introduce some of the basic concepts behind WebSockets (including an example URL) and show how to use the PHPWebSockets library to handle some sample requests. They also include some basic JavaScript to make the request to the backend PHP script and send or fetch content on the server. They also show you how to implement a simple chat server using a few other libraries like Ratchet, Elephpant.io and Socket.io.

tagged: realtime application websockets tutorial introudction

Link: http://www.phpbuilder.com/articles/application-architecture/optimization/creating-real-time-applications-with-php-and-websockets.html

Gonzalo Ayuso:
Integrating WebSockets with PHP applications. Silex and socket.io playing together.
Feb 04, 2014 @ 09:37:25

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.

tagged: websockets socketio silex websockets tutorial authentication security

Link: http://gonzalo123.com/2013/12/24/integrating-websockets-with-php-applications-silex-and-socket-io-playing-together

Gonzalo Ayuso:
Integrating WebSockets with PHP applications. Silex and socket.io playing together.
Feb 04, 2014 @ 09:37:25

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.

tagged: websockets socketio silex websockets tutorial authentication security

Link: http://gonzalo123.com/2013/12/24/integrating-websockets-with-php-applications-silex-and-socket-io-playing-together

SitePoint PHP Blog:
Building a Live-score Widget Using PHP Web Sockets
Oct 17, 2013 @ 10:11:42

On the SitePoint PHP blog there's a new post from Lukas White about using PHP and web sockets to create a "live score" widget to include in your site.

The introduction of web sockets makes it possible for web applications to handle near real-time data without resorting to "hacks" such as long-polling. One example of an application requiring up-to-the-minute data is sports scores. Even now, many websites which display this information use Flash applications, since Actionscript provides the facility to communicate over socket-based connections. However, web sockets allow us to replicate this functionality using only HTML and Javascript. That's what we're going to build in this tutorial, along with a lightweight "server" in PHP.

His example uses the Ratchet PHP library to provide the WebSockets functionality to the frontend script polling for the latest data. He helps you get the library installed and set up a simple directory structure for the example. He includes sample scripts for both the data provider (for the scores) and the WebSocket provider. He talks about maintaining the state of the data and shows how to pull out random data from a set of fixtures (pre-defined data) to send back to the frontend. The Javascript for the frontend script is also included.

tagged: tutorial websockets live score example javascript ratchet

Link: http://www.sitepoint.com/building-live-score-widget-using-php-web-sockets/

7PHP.com:
Win (TWO) Free Tickets To Hear Corey Ballou (Creating Realtime Applications w/Web Sockets)
Jul 15, 2013 @ 10:03:02

There's a new post on 7PHP.com talking about a new giveaway they're doing in collaboration with the Nomad PHP (virtual) user group and giving away two tickets for the upcoming meeting.

NomadPHP is already on their 3rd edition and I’m hence also on my 3rd Ticket(s) give-away. [...] The topic of this 3rd talk will be centered around PHP and Websockets and will be presented by speaker Corey Ballou.

There's two ways to enter into the contest - either subscribe to their mailing list or Tweet about it (with the given tweet). The contest ends July 21st, so hurry and enter if you're interested. The Nomad PHP user group is "a (virtual) place to call home" if you don't have a user group in your area. It meets online once a month.

tagged: contest tickets coreyballou realitme websockets nomadphp

Link: http://7php.com/nomadphp-july-2013-free-tickets

Nomad PHP July 2013:
Corey Ballou - Creating Realtime Applications with PHP and Websockets
Jul 04, 2013 @ 13:19:26

The Nomad PHP virtual user group has announce the latest meeting - this time it's Corey Ballou presenting about realtime applications and WebSockets in July.

We’ll start out with a brief introduction to WebSockets to get everyone up to speed before jumping in to high level scaffolding code of the frontend and backend implemetations (the spec). Once the groundwork has been laid, I’ll introduce you to a both client and server side tools for implementing WebSockets directly in your PHP code. From here, we’ll jump into multiple interactive demos of increasing complexity utilizing the open source Ratchet library. I’ll walk through the source code of the first two intro demos to give you a better sense of how to structure your own WebSockets applications

If time allows, I’ll run through a complex demo where I introduced WebSockets to an existing CRUD todo application. The last demo is not for the faint of heart. By the end of the presentation, you’ll walk away with access to a github repository containing all of the presentation slides and demos ready to run yourself!

You can pick up your tickets for this meeting (happening July 25th) directly from the Nomad PHP site.

tagged: nomadphp coreyballlou realtime applications websockets virtual usergroup

Link: http://nomadphp.com/2013/06/06/july-2013/

PHP Town Hall Podcast:
Episode #7 - Web Sockets Are Fast
May 20, 2013 @ 11:41:55

The PHP Town Hall podcast has posted a new episode - Episode #7: "Web Sockets Are Fast".

Chris Boden joins us to talk about a Ratchet and React. The conversation is basically Ben and Phil asking a bunch of questions about how Ratchet works, pretending we know what is going on while Chris uses lots of words like “concurrency” and “non-blocking”. We decide that PHP is web-scale, event-driven programming is not just for NodeJS hipsters, we all take the “Are You a Brogrammer” test and Michael Wales crashes the show half way through like a ninja.

You can listen to this latest episode either through the in-page player or by downloading the episode directly. You can also subscribe to their feed if you'd like the latest shows as they're released.

tagged: podcast phptownhall websockets philsturgeon benedmunds

Link: http://phptownhall.com//blog/2013/06/18/episode-7-web-sockets-are-fast

Web & PHP Magazine:
Issue #12 - Don't Get in a PECL
Mar 08, 2013 @ 10:23:36

The latest issue of the Web and PHP Magazine has been published - issue #12, "Don't get in a PECL". This latest issue includes articles like:

  • "The Power of PECL" by Simon Holywell
  • "Be 'ready' if you want to be done!" by Steffan Surdek
  • "All Data is Relational" by Cory Isaacson
  • "Fixing PHP Production Problems with APM" by Dan Delany and Chris Kelly
  • "Trust" by Sebastian Bergmann

You can download your copy for free from their site and catch up on back issues.

tagged: webandphpmagazine issue pecl recursion relational data websockets

Link: