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

Marc Scholten:
Accidental Complexity Caused By Service Containers In The PHP World
May 24, 2016 @ 11:25:30

In this post to his site Marc Scholten talks about something that's become a side effect of using the inversion of control design pattern in PHP applications (specifically related to dependency injection): added accidental complexity.

Modern PHP development favors the use of inversion of control to keep software more configurable and flexible. This leads to the problem that one now has to create a big graph of objects to use the application. As a solution to avoid redundant setup code, service containers like the symfony2 dependency injection component are used.

The goal of a service container is to centralize the construction of big object graphs. [...] Simple, right? Actually it’s not. Commonly used service containers are complex solution for simple problems.

He illustrates with an example using the Symfony services container, a piece of the framework that allows the definition of dependency relationships via a YAML formatted file. While this configuration seems simple enough, he points out that more complex dependencies (ones that could easier be set via a "set" method) become more difficult to define when limited by the service container config structure. He also points out that it makes static analysis of the code much more difficult with dependencies being dynamically fetched from the container instead of directly related. He offers an alternative to this complex container setup, however: a simple method (or methods) inside of a factory class that creates the objects, injects the required dependencies. This makes it much easier to call from the service container instance and configuration and even a "create container" call to set all of the dependencies up at once. He ends the post with some advantages of this approach and a takeaway or two to keep in mind when managing your object dependencies.

tagged: complexity service container accidental configuration simplex complex example symfony

Link: https://www.mpscholten.de/software-engineering/2016/05/21/accidental-complexity-caused-by-service-containers-in-the-php-world.html

Symfony Blog:
The New Symfony Documentation Search Engine
Apr 29, 2016 @ 10:49:27

In an effort to improve their "developer experience" (DX) around using the Symfony framework the development team has introduced new searching functionality to help more effectively find what you're looking for in the expansive Symfony documentation.

Symfony boasts one of the largest documentation pools ever written for an Open- Source project. Considering the ten different Symfony versions (from 2.0 to master) and including the code samples, Symfony Documentation has around 3.6 million words, more than three times the word count of the entire Harry Potter series.

They share some of the things they learned around creating a search engine ("it's hard") and what they ultimately ended up using - the Algolia service. The post talks about how they indexed the current documentation and broke it up into "chunks" of meaningful content. They also include the simple Javascript they use that links the search field to the Algolia service and renders the results using a view partial.

The proof of concept for the new search engine was a success and we decided to stop the ElasticSearch integration and stick with Algolia. The new search engine is greatly faster than the previous one and the search results are more accurate and relevant.
tagged: symfony documentation search engine new algolia service

Link: http://symfony.com/blog/the-new-symfony-documentation-search-engine

Matt Stauffer:
Using SparkPost for Transactional emails with Laravel
Apr 27, 2016 @ 10:54:42

Matt Stauffer has a post to his site for the Laravel users out there wanting to seed "transactional emails" from their applications. In this tutorial he shows you how to use the SparkPost service to send emails with very little effort.

Recently, Mandrill announced that they'd be sunsetting their transactional email service and instead rolling it in to a secondary service for paid MailChimp users. That's fine for them, but many of us were using it for small one-off apps and weren't interested in all of a sudden paying money to send 100 emails a month.

[...] But right when Mandrill announced their pricing change, a new transactional email provider came out of nowhere: SparkPost. [...] So let's walk through the process of signing up and moving Giscus, my app for notifying you of comments on your gists, from Mandrill to SparkPost.

First he walks you through the process of getting a SparkPost account set up and configured to receive messages from your application. He then moves over to the Laravel side, upgrades his installed version and configures it with the "secret" value SparkPost provides and changes the MAIL_DRIVER value - that's basically it.. He also includes some screenshots of other parts of the SparkPost admin interface to show some of the other functionality included.

tagged: tutorial laravel sparkpost service transaction email send

Link: https://mattstauffer.co/blog/using-sparkpost-for-transactional-emails-with-laravel

php[architect]:
Mandrill Alternatives for PHP Applications
Apr 19, 2016 @ 12:07:16

With the recent (well, not too recent) announcement from MailChimp about the shift to a paid model for their Mandrill email service, PHP developers have been busy looking for alternatives. In this post to the php[architect] site Sandy Smith explores some of the other options out there, how they compare and what they have to offer.

n case you might have missed the announcement, MailChimp is changing Mandrill to be an add-on to paid MailChimp accounts, thus eliminating the generous free tier. We’re big fans of MailChimp and use its mailing list service for our own announcements, but a full MailChimp account isn’t going to be for everybody. [...] Many people also know Mandrill by reputation and will need options in the future. For you, we’ve put together this list of viable transactional email alternatives with PHP and major PHP application support.

Included in their list are services like:

For each service he includes a paragraph talking about what integrations and libraries there are for their use as well as what's included in their "free" levels.

tagged: mandrill alternative email service options sdk overview

Link: https://www.phparch.com/2016/04/mandrill-alternatives-for-php-applications/

Symfony Finland:
Why have Controllers as Services in Symfony?
Feb 29, 2016 @ 09:13:05

On the Symfony Finland blog there's a post that talks about Symfony controllers and services and how making the controllers services instead could be beneficial.

Controllers are quite straightforward in their actions (ha-ha) and simply take requests and return responses. The concept of a services is simple too, it's technically just a PHP object that performs a task over and over again somewhere in your application.

[...] Using services for tasks repeating in multiple locations of your application undoubtedly makes sense, but why should you shrinkwrap your controllers into a service? If you look at the official Symfony Demo Application does not do this. So why should yours?

Once again he uses the eZ Platform software to illustrate the point, describing how it packages up the controllers into services, including the configuration required to make it work. He shows how the dependency injection works and how controllers/services can call actions in other controllers/services easily.

tagged: controller service symfony ezplatform tutorial configuration yaml

Link: https://www.symfony.fi/entry/why-have-controllers-as-services-in-symfony

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:
Foreign Data Wrappers with PostgreSQL and PHP
Feb 22, 2016 @ 09:43:48

Gonzalo Ayuso has posted a quick tutorial to his site showing you how to work with Foreign Data Wrappers on your PostgreSQL database in PHP. If you're not familiar with the data wrappers functionality, you can find out more on the PostgreSQL wiki.

PostgreSQL is more than a relational database. It has many cool features. Today we’re going to play with Foreign Data Wrappers (FDW). The idea is crate a virtual table from an external datasource and use it like we use a traditional table.

He gives an example of a simple RESTful service with a Silex application serving up a set of user data (names). He then switches over to the PostgreSQL side and shows how to create the data wrapper and set up the mapping of it to the REST server's location. With that set up you can then select from the data returned as if it were a normal table with a slight caveat - filtering (like with where) must be done server side, not via the SQL statement.

tagged: postgresql tutorial foreigndatawrapper datawrapper database rest service

Link: http://gonzalo123.com/2016/02/22/foreign-data-wrappers-with-postgresql-and-php/

SitePoint PHP Blog:
An in-Depth Walkthrough of Supercharging Apps with Blackfire
Jan 14, 2016 @ 11:30:32

The SitePoint PHP blog has a new tutorial posted by Reza Lavaryan showing you how to "supercharge your applications" with the help of the Blackfire.io profiling service.

With profiling, we can spot the performance bottlenecks in the code and do something about them. There is a variety of profiling tools out there, each taking a different approach. [...] With profiling, we can spot the performance bottlenecks in the code and do something about them. There is a variety of profiling tools out there, each taking a different approach. [...] Blackfire.io is the new generation of web profilers, which takes the automatic instrumentation approach, but without imposing a performance impact on our application.

First he defines some of the basic terms it's helpful to know when profiling and using Blackfire. He then walks you through getting what you'll need set up:

  • a Homestead VM instance with the necessary configuration options
  • a script using Faker to generate and write user data to a local database

He then shows you how to execute the first profiling run and what the results look like in the Blackfire views. He uses these results to make some modifications to the script and re-runs the tests to see what kind of gains it provides. Most of his examples use the web interface for the service but the post ends with a look at using the command line tool and getting back some simple metrics as a result.

tagged: profiling performance evaluate blackfireio service introduction faker

Link: http://www.sitepoint.com/an-in-depth-walkthrough-of-supercharging-apps-with-blackfire/

Laravel News:
Automatically upgrade your Laravel app with Shift
Jan 06, 2016 @ 10:24:52

On the Laravel News site they've posted an interview with Jason McCreary, the lead developer behind the Laravel Shift service, a product that helps you keep your Laravel applications up to date with the latest versions of the framework.

Laravel Shift is a new project aimed at automatically upgrading out of date Laravel apps up to the current version. The way it works is you sign-in with either Github or BitBucket, purchase a shift (an upgrade package), and then review the pull request it automatically creates.

I had a chance to speak with Jason, the lead developer on the project and what follows is a Q&A about Shift.

They talk about where the idea for Laravel Shift came from originally and how the upgrade process happens (hint: it's automated). Jason also answers questions about what kinds of applications it will work on and how it's handled if there's an application that can't be upgraded. He also mentions the process for upgrading from a very old version, noting that it would be required to "shift" multiple times to achieve the correct results.

tagged: laravel shift service upgrade automatic application laravelnews

Link: https://laravel-news.com/2016/01/automatically-upgrade-your-laravel-app-with-shift/

SitePoint PHP Blog:
Introducing Bugsnag – the Last Error Monitor You’ll Need
Jan 05, 2016 @ 11:12:53

The SitePoint PHP blog there's a tutorial posted showing you how to integrate your application with Bugsnag, the "last error monitor you'll need". Bugsnag is an external service that provides you more insight into the errors in your application and statistics around them.

The pursuit of building an error-free application continues. But in the meanwhile, we need to monitor our application’s errors and take action quickly. Many companies have tried to solve this problem, and one of the best on the market right now is Bugsnag. [...] In this article, we’re going to discover Bugsnag and integrate it into an existing Laravel application. You can clone the demo app from Github to follow along.

The article walks you through the setup of the demo application (cloned from GitHub) and the creation of a Bugsnag account with a 30 day free trial. It then shows how to integrate the PHP notifier package into your application, though the sample application is Laravel-based so they show how to use this package in the examples. From there they show how to provide your credentials, set up the environment for the app (ex: production, development, etc) and methods for sending various messages types and content over to the service. The post then looks at the Bugsnag dashboard, giving a brief overview of how it looks and what features it includes.

tagged: bugsnag tutorial integration laravel error monitoring service thirdparty

Link: http://www.sitepoint.com/laravel-with-bugsnag-the-last-error-monitor-youll-need/