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

BitExpert Blog:
Mattermost Webhooks and PHP
Jul 19, 2017 @ 10:49:26

On the BitExpert blog Stephan Hochdörfer shares his experience working with Mattermost webhooks and interfacing them with backend PHP scripts. Mattermost is an Open Source Slack clone.

In a recent attempt to automate a few things even more, I was looking for a way to post messages to our [Mattermost](http://mattermost.org/) instance via the [Incoming Webhook](https://docs.mattermost.com/developer/webhooks-incoming.html) feature of Mattermost. I did a quick search on [Packagist](https://packagist.org/search/?q=mattermost) for Mattermost client libraries and as it turns out there a quite a few. I picked the [thibaud-dauce/mattermost-php](https://packagist.org/packages/thibaud-dauce/mattermost-php) package simply because it was the first match.

He then walks through the installation of the package and how it works, using Guzzle, to send messages to the Mattermost service. The incoming request is just a JSON-formatted data set, so it's easily parsed in plain PHP. The output, however, needs to be in a format Mattermost understands. That's where the package comes in, providing a "send" method that allows for the customized text and optional attachment to be sent to the Mattermost server.

tagged: mattermost package webhook messaging message tutorial

Link: https://blog.bitexpert.de/blog/mattermost-webhooks-and-php/

Laravel News:
Echo is coming to Laravel 5.3
May 13, 2016 @ 11:07:09

On the Laravel News site there's a post talking about a feature coming in the 5.3 version of the Laravel framework - Laravel Echo (not a separate system, just an enhancement inside the framework).

Laravel Echo is coming to Laravel 5.3 and is designed to be an improvement over the current event broadcasting system. [...] In this video, Taylor steps through the features by demoing a little to do app. You can see the full source code to the demo on GitHub.

Echo is essentially an improvement on the in-application messaging to provide more real-time feedback between users in the system. In his demo, he makes use of the Vue.js framework heavily and custom broadcasters and Pusher.

tagged: laravel echo realtime messaging

Link: https://laravel-news.com/2016/05/echo-coming-laravel-5-3/

Madewithlove Blog:
Thread carefully
Nov 16, 2015 @ 11:55:58

In a post to the Madewithlove blog Maxime Fabre takes a look at threading in PHP using the pthreads support that can be included into your PHP installation.

As far as I can remember, PHP has always had a terrible reputation at handling very heavy (or asynchronous) tasks. [...] But PHP can do threading, and more importantly it's a lot easier than you probably think.

[...] In this article I'm going to dive into the pthreads extension (short for POSIX Threads). It has been around for a while (since 2012) but I feel like too many people forget it exists or assume it is going to be painful to use – mostly because the official documentation is rather slim about it.

They start by getting the pthreads support installed locally (it assumes you use OS X and the "brew" package manager but it can be installed manually too). The article starts off by defining some basic nomenclature from the pthreads world and gives a diagram of how it all fits together. From there it gets into some examples, showing a simple thread class to fetch Google results and how to fire off multiple instances at the same time. They then extend this even further and look at the concept of "workers" and using them to manage individual jobs. It then moves up the next level and looks at "pools" of workers and processing multiple workers at the same time.

There's also a section dealing with one "gotcha" that can happen with class inheritance between parent and child threads. They show how to work around this with a custom Worker class that performs the autoloading for you and is executed at the start of a Pool. Finally they cover the messaging between the child threads and, as a bonus, how threading could be used in a command bus setup.

tagged: threading tutorial pthreads example worker thread pool process commandbus messaging

Link: http://blog.madewithlove.be/post/thread-carefully/

Creating a Dating Application with Sinch: RESTful API
Apr 27, 2015 @ 10:19:26

NetTuts.com has kicked off a new tutorial series today about building a dating application with a combination of Laravel, MongoDB and the Sinch service allowing for messaging between users. The Sinch service has several features including voice/messaging/SMS communication methods and device verification.

In this tutorial, we're going to create a dating application for iOS similar to Tinder. For voice and messaging, we will leverage the Sinch platform, making use of its powerful SDK. In the first part, we will focus on the development of a RESTful API to store and retrieve user information. In the second part, the iOS client will hook into this API to find nearby users based on the user's current location. We will use Laravel 5.0 for the RESTful service and will be covering basic concepts, such as routes and controllers. We are also going to define custom models to support MongoDB integration in an ActiveRecord-like manner.

This first part of the series is mostly about just getting things set up so they walk you through:

  • Basic setup of the Laravel application
  • Creation of the Base model (for MongoDB connection)
  • Creating helper methods
  • Building out CRUD functionality for the database layer
  • Making a User model
  • Creating the BaseController class
  • Making a SessionController class (and working with sessions)
  • Building a UserController

They end this part of the series by hooking all of this functionality together with some simple RESTful routing for GET, POST, PUT and DELETE request handling for the various endpoints.

tagged: tutorial series laravel sinch messaging rest api framework part1

Link: http://code.tutsplus.com/tutorials/creating-a-dating-application-with-sinch-restful-api--cms-23709

Coder on Code:
Design Patterns in PHP: Adapters
Jan 26, 2015 @ 10:46:42

The Coder on Code site has posted a new tutorial covering the Adapter design pattern in detail. They talk about what the pattern is, what it can be useful for and include some code to illustrate.

The adapter pattern also referred as the wrapper pattern, I find that wrapper is a more fitting name since it describes clearly what this pattern does; it encapsulates the functionality of a class or object into a class with a common public interfaces. [...] Adapters are one of the easiest patterns to comprehend and at the same time one of the most useful ones.

He starts with some of the basic definitions of terms involved in the pattern: client, adapter and adapteee. His example centers around a notification manager class that lets you switch types between Twitter, Email and SMS messaging. His initial code has all of the message types handled in one class method. He shows how to refactor this out to an interface and a set of child classes, each with the corresponding handling in a "sendNotification" method. These are then used by an adapter in the main class to send the given message. This simplifies the main messenger class and contributes to the overall improvement of architecture and testability of the application.

tagged: designpattern adapter example introduction client adapter adaptee messaging tutorial

Link: http://coderoncode.com/2015/01/25/design-patterns-in-php-adapters.html

Twilio Blog:
How to Build an MMS Ticketing System Using PHP, Laravel and Twilio
Oct 03, 2014 @ 12:18:54

On the Twilio blog there's a recent post showing the construction of some fundamental parts of a MMS ticketing system using Laravel and Twilio for the messaging.

Have you ever arrived at a movie, flight or concert and realized you’ve forgotten your paper ticket? Imagine how much worse it would be if you showed up at Willy Wonka’s front door, but forgot your golden ticket! To prevent an epic disaster such as this, we’re going to build an app that delivers Willy Wonka’s golden ticket directly to your phone using MMS. All the Oompa Loompas have to do is scan it. Not Willy Wonka? Don’t worry, this code should be useful for any app or company that distributes tickets. Hopefully computers are more helpful with the golden ticket than last time.

The application makes use of a few libraries outside of the Laravel framework structure to handle the various functional pieces: one for creating QR codes and another for sending the messages via Twilio. They walk through some of the basic setup for the first endpoint and the "Golden Ticket Distribution" page. He then uses the Endroid QR code library to generate a code based on a string and outputting it to the user. Using a few pieces of data from the URL (in $_GET), they define the phone number to send to and the name of the user. Finally they tie it into the Twilio messaging system and send the MMS message containing the resulting QR code.

tagged: twilio mms messaging qr code library tutorial laravel

Link: https://www.twilio.com/blog/2014/09/how-to-build-an-mms-ticketing-system-using-php-laravel-and-twilio.html

Creating a Photo Tag Wall With Twilio Picture Messaging & PHP
Jan 10, 2014 @ 10:36:00

On NetTuts.com today there's a new tutorial that helps you create a "photo tag wall" using the Twilio picture messaging functionality and some PHP. The picture messaging service lets you send and receive photos over phone numbers and short codes.

Twilio’s recently announced Picture Messaging has vastly opened up what we can do with text messaging, now we can attach photos to our text messages and have them get used in different ways. In our case, we are going to build a Photo Tag Wall, which will contain photos linked to tags that will be displayed on a website. This can be handy for events, or parties, or just about anything where you want to associate photos and tags.

They use a combination of the Jolt microframework for the structure of the app, Idiorm/Paris for the MySQL handling and the Twilio PHP library to talk to their web service. They start by setting up the database tables for both the "tag" and "photo" (SQL included). They include a sample configuration file, used by the Twilio library, and get into the actual code. The first part shows how to make the request to the API and resize the fetched data into a correctly sized photo on the server. Then they get into the routing, making both a root path and a "listener" for the Twilio API to call when a new photo it sent. Finally, they set up the actual photo wall page, pulling the image data from the database and the image from the local file system.

tagged: photo tag wall tutorial twilio picture messaging mysql

Link: http://net.tutsplus.com/tutorials/php/creating-a-photo-tag-wall-with-twilio-picture-messaging-php

Lorenzo Alberton:
Updated Kafka PHP client library
Sep 18, 2012 @ 11:58:50

Lorenzo Alberton has a new post with an update about a library he's been working on to interface with Apache's Kafka system, "a persistent, distributed, high-throughput publish-subscribe messaging system".

Over a year ago I sort of reverse-engineered the protocol, and published a first rudimental library to produce and consume messages with version 0.05. Since then, the Kafka project has evolved a lot, moving from the LinkedIN repositories to the Apache Incubator, gaining traction, committers, features. The protocol has changed slightly too, so the old library doesn't work anymore with the new version (0.6+).

The library has gotten lots of new features in this update including gzip compression support, custom exception handling and better connection handling. He includes some sample code in the post showing how to create both the Producer and Consumer for the messages (and one for working with Zookeeper).

tagged: kafka client apache messaging producer consumer library update


Getting Real-Time with Pusher
Oct 05, 2011 @ 08:39:52

On NetTuts.com today there's a new tutorial showing you how to implement the Pusher service that gives you real-time messaging for your application. Their backend for the project is written in PHP using Pusher's library.

Do you want to spice up your web applications by making them real-time - but don’t want to create new infrastructures for the sole purpose of getting web sockets to work? In this article, we’ll explore how to use and implement Pusher, an HTML5 WebSocket-powered real-time messaging service for your applications.

Pusher uses HTML5 WebSockets to handle the messaging, so you'll need a browser that supports it to follow along with the tutorial. The Pusher API provides and endpoint for authorization and the push and pull of messages. In the tutorial, they create a simple chat application that gives a "Who's Online" and a window with the latest messages. You can download the full source (Javascript and PHP) here or view a demo here.

tagged: realtime messaging pusher service websockets tutorial


Bradley Holt's Blog:
Exploring RabbitMQ and PHP
Jul 21, 2011 @ 09:13:17

In a new post Bradley Holt looks at some of his exploration into the combination of RabbitMQ and PHP as a possible platform for messaging between process (or applications).

I’m exploring the possibility of using RabbitMQ for an upcoming project. RabbitMQ is a free/open source message broker platform. It uses the open Advanced Message Queuing Protocol (AMQP) standard and is written in Erlang using the Open Telecom Platform (OTP). It promises a high level of availability, throughput, scalability, and portability. Since it is built using open standards, it is interoperable with other messaging systems and can be accessed from any platform.

He goes through the full process - installing RabbitMQ via MacPorts, grabbing the latest copy of the librabbitmq library and installing it and finally installing the AMQP extension for PHP so they can communicate. He includes some simple code that connects to the queue and sends a "hello world" message out to the connection bound to "routeA".

tagged: rabbitmq messaging protocol platform tutorial extension librabbitmq pecl