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

SitePont PHP Blog:
How to Quickly Build a Chat App with Ratchet
Sep 28, 2015 @ 10:52:41

On the SitePoint PHP blog they've posted a tutorial showing you how to build a chat application with Ratchet, a library in PHP that lets you work with WebSockets for more real-time communication between your frontend and backend systems.

In this tutorial, we’ll be taking a look at Ratchet, a PHP library for working with WebSockets. Let’s start by defining what WebSockets are. MDN says: "WebSockets is an advanced technology that makes it possible to open an interactive communication session between the user’s browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply. Connected computers image."

WebSockets allow us to write applications that can pass data from the browser to the server and vice-versa in real-time.

They start by helping you get Ratchet installed (via Composer) and start immediate in on the code. They create the application namespace, a Chat class and client to handle the WebSocket connection. They create methods for the open, close, write and read for the connection and make a simple script with a Ratchet server to handle the messaging back and forth. They also explain the various pieces of the system: the IoServer, HttpServer and WsServer. Finally they help you create the HTML frontend (using jQuery and Handlebars) and the CSS/Javascript to finish off the functionality.

tagged: ratchet websocket realtime chat application tutorial library

Link: http://www.sitepoint.com/how-to-quickly-build-a-chat-app-with-ratchet/

Pusher Blog:
How to Build Real-Time Laravel Apps with Pusher
Sep 23, 2015 @ 10:22:31

The Pusher blog has posted the set of tutorials they created as a part of the Laracon EU conference that shows you how to use their service to create a real-time Laravel-based application - a simple chat application.

The Laravel framework and Pusher are a great combination. Laravel helps you build elegant applications and at warp speed; Pusher helps you add real-time features to those apps in a fraction of the time it would take to build using your own infrastructure. [...] We recently wrote a set of tutorials covering How to Build Real-Time Laravel Apps with Pusher as part of a Workshop for Laracon EU. We’ve now opened up these tutorials for everybody and anybody to work through. The source has been opened up under the Commons Attribution 4.0 International License so you’re free to fork and adapt to suit your needs or even to run your own workshop.

The talk briefly about who the tutorials are targeted at and how the guide is laid out (a Gitbook). It covers some of the fundamentals of Pusher, setting it up via a Laravel bridge, debugging tips and the construction of the actual sample application.

tagged: pusher realtime application tutorial series gitbook chat laravel

Link: https://blog.pusher.com/how-to-build-real-time-laravel-apps-with-pusher/

SitePoint PHP Blog:
Logging with Monolog: From Devtools to Slack
Sep 02, 2015 @ 11:48:15

The SitePoint PHP blog has posted a tutorial showing you how to connect Monolog with Slack, a popular logging tool for PHP and a well-used communication (chat) service for development groups and projects. The basic idea is that, when something goes wrong, it's communicated directly to the chat channel versus just to a log somewhere for later analysis.

Logging is an important part of the app development/maintenance cycle. It’s not just about the data you log, but also about how you do it. In this article, we are going to explore the Monolog package and see how it can help us take advantage of our logs.

They start by helping you get Monolog installed in your project via Composer and how to create their "general" logger. He then explains the use of "handlers" in the Monolog system and how to add them to the logger instance. They also explain Monolog's "bubbling" of messages in a browser/error log example. Next they show how to integrate the SlackHandler into the logger, providing it with an access token, the channel to send to and a name to log in with. The article also shows how to format the message, giving it a bit nicer look than just the standard text error. Finally they touch on preprocessors that can add extra information to the log messages without having to touch every instance where it's used.

tagged: monolog slack integration message error realtime chat introduction

Link: http://www.sitepoint.com/logging-with-monolog-from-devtools-to-slack/

Build a Real-Time Chat Application With Modulus and Laravel 5
Sep 02, 2015 @ 10:17:16

On NetTuts.com they've posted a tutorial showing you how to create a real-time chat system using Laravel 5, Modulus and Pusher (with a PostregSQL backend).

In this tutorial, I will show you how to implement a real-time chat application with Laravel 5, PostgreSQL, and Pusher. Then we will deploy this application to Modulus together. We will use Laravel 5 for the back-end service, HTML5 and jQuery for a simple front-end application, PostgreSQL for the database, and Pusher for real-time communication between the server and clients.

They start with the scenario they want to solve and a look at the overall architecture of the solution. Then they start setting up the software and services needed to bring it all together:

  • installing a fresh copy of Laravel (as a project)
  • setting up a new database using the ElephantSQL service
  • creating a Pusher account and the credentials you'll need for the application
  • creating an Nginx configuration for the Modulus setup

Next comes the design of the application, creating the models for message data (author, content, etc) and the simple controller to handle the requests. They show how to configure the connection to Pusher and build the routes for getting, listing and saving messages. Finally they create the view complete with Javascript to connect it to Pusher and transfer messages back and forth. All that's left then is the deployment using the modulus command line tool (installed via npm).

tagged: realtime chat tutorial application laravel5 pusher postgresql modulus

Link: http://code.tutsplus.com/tutorials/build-a-real-time-chat-application-with-modulus-and-laravel-5--cms-24284

SitePoint PHP Blog:
Real-time Apps with Laravel 5.1 and Event Broadcasting
Jun 10, 2015 @ 11:53:38

SitePoint's PHP Blog has a new tutorial posted showing you how to use event broadcasting in Laravel 5 to perform actions based on events the application issues.

In Laravel 5.1, the framework includes functionality called broadcasting events that makes it easy to create real-time apps in PHP. With this new functionality, an app can publish events to various cloud-based real-time PubSub solutions, like Pusher, or to Redis.

They start you off installing their sample application inside of a Homestead Improved virtual machine. They show you how to use the non-realtime version of the application and how the other parts of the application do not update when changes are made. They then create the ItemCreated, ItemUpdated and ItemDeleted events and the related data provider needed to "boot" the events. From there they walk you through installing the Pusher PHP library, including the matching Javascript file and a bit of code to push events and receive them in other parts of your application.

tagged: tutorial laravel5 realtime application pusher event broadcasting

Link: http://www.sitepoint.com/real-time-apps-laravel-5-1-event-broadcasting/

Kevin Schroeder:
Realtime logging for Magento
Jan 14, 2015 @ 09:47:54

Kevin Schroeder has a new post to his site talking about real-time Magento logging and a library he's worked up to make it possible.

Ever since the Zend Developer Cloud started up it stirred in me some really interesting possibilities of what could be done. Sadly they never happened, but the ideas remained. If that doesn’t inspire you it’s because I’m not describing what I have in my head. I don’t have the time to do that. But this blog post is one part of it. One of the things that is part of what I envision is a realtime logger that shows what is happening, as it is happening. [Zend Server ZRay is] a cool feature but doesn’t quite go as far as I have in mind.

With that in mind I spent some time last week working on a very small piece of this vision for Magento. I wrote it really, really quickly and so don’t laugh when you look at the code and see obvious errors.

The library makes use of Magento extension and a command line program that uses a combo of Redis and PubSub for messaging back to the waiting logger. It hooks into all Magento events and allows for writing to the log from just about anywhere. It also includes a SQL profiler that will evaluate requests either in real-time or at the end of the request. He provides some additional details about the "watcher" command line tool and explanations for each of its options.

tagged: magento realtime logging library commandline tool

Link: http://www.eschrade.com/page/realtime-logging-for-magento/

Building With the Twitter API: Using Real-Time Streams
Nov 18, 2014 @ 11:28:14

NetTuts.com finishes off their series covering how to connect your application to Twitter and pull data. In this latest tutorial they show the use of the real-time streams Twitter offers to those needing the most up-to-date and immediate access to tweets via a command-line tool. This tutorial makes use of the Yii PHP framework for it's execution.

While the Twitter REST API is suitable for many applications, if you want immediate updates and access to a broader array of notifications, the Twitter Streaming API is essential. For example, only the streaming API will tell you when another user favorites one of your tweets. Using the Streaming API requires a persistent, keep-alive connection between your web server and Twitter. This type of implementation may be unfamiliar to many PHP developers. As soon as tweets come in, Twitter notifies your server in real time, allowing you to store them into your database without the delay of polling the REST API. Use of the Streaming API is also not subject to Twitter's API rate limits.

They start with a brief description of the Streams functionality and provide a graphic showing the overview of the data flow when you put them to use. They make use of the phirehose library to make the connection (making it almost a two-step method: connect & consume). They walk you through the creation of a Yii command to create the command and set it up for execution. They show you how to integrate it into a larger Yii application, create a migration to store the data and execute the resulting code as a long running command.

tagged: realtime streams twitter tutorial series phirehose connect consume

Link: http://code.tutsplus.com/tutorials/building-with-the-twitter-api-using-real-time-streams--cms-22194

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

SitePoint PHP Blog:
Paginating Real-Time Data with Cursor Based Pagination
Jul 11, 2014 @ 11:52:13

On the SitePoint PHP blog today a new tutorial has been posted introducing you to cursor-based pagination of real-time data, showing the results and allowing for easy click-through functionality.

Pagination is a technique for breaking large record sets into smaller portions called pages. As a developer, you should be familiar with implementing pagination, but implementing pagination for real time data can become tricky even for experienced developers. In this tutorial, we are going to discuss the practical use cases and solutions for real time data pagination and cursor based pagination.

He uses results from the Twitter and Facebook APIs in his examples, grabbing tweets matching the search term "php". He briefly explains some of the issues with real-time pagination and how it compares with standard pagination techniques. He uses the "after" and "before" functionality of each API to only pull the data needed, not the entire list of latest posts. This is added to a list in order and shown when the user view is refreshed. He includes the code for implementing the cursor-based handling and how to echo the results back out to a view.

tagged: cursor pagination twitter facebook api tutorial realtime

Link: http://www.sitepoint.com/paginating-real-time-data-cursor-based-pagination/

Joshua Thijssen:
Realtime PHPUnit
Feb 05, 2014 @ 09:22:52

Joshua Thijssen has a new post to his site sharing an interesting tool for those using PHPUnit for testing. It's a real-time plugin that executes your tests as soon as something in your files change.

Not all IDEs (actually, i haven’t seen even one IDE that does this), can run your unit-tests as soon as something changes. Inspired by Greg Young’s Mighty Moose system, the following script runs inside a shell, will wait for changes in your PHP-files, and runs the corresponding unit-test as soon as something changes. It doesn’t run the WHOLE unit-tests suite, but merely the test that matches up the source file.

His tool, found here on Github and uses a simple bash script that uses the file name being saved to locate the matching test and execute it, reporting back any errors that might have popped up. This could easily be hooked into most IDEs out there and keep the developer in one place.

tagged: realtime phpunit bash script

Link: https://www.adayinthelifeof.nl/2014/02/02/realtime-phpunit/