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

SitePoint PHP Blog:
Sending PHP Event Messages to Remote Logstash on Windows
Dec 05, 2016 @ 12:20:09

The SitePoint PHP blog has a recently posted tutorial showing you how to send event messages from PHP to a remote Logstash server running your PHP on a system with Windows installed. Logstash's goal is to centralize the logging in your environment, allowing you to input log information from a wide range of sources and stored in an Elasticsearch database.

By opening this article you’ve endeavored yourself to expanding your knowledge of PHP applications as part of event-based distributed systems. You’ll be given a quick intro into what we are referring to when we say event messages, what Logstash is, and why it is so cool.

If you’ve already heard of Beats or understand you can run Logstash locally to ship logs to another Logstash instance or directly to a datastore such as Elasticsearch, this article is still for you and will show you an easy-to-configure-and-run, hopefully more effective and certainly fun-to-use alternative.

They start with the quick introduction to Logstash and how the event handling they'll add in later will relay messages over to the waiting server. A code example is included showing how to manually write to rsyslog, pointing out that it and Logstash use a similar protocol to receive messages. The tutorial then shows how to view the messages in the log to ensure they're making it correctly and how to use this agent to stream messages over to the waiting server.

tagged: sitepoint event messages remote logstash windows agent tutorial

Link: https://www.sitepoint.com/sending-php-event-messages-to-remote-logstash-on-windows/

Ben Ramsey:
Building PHP Projects on AWS CodeBuild
Dec 05, 2016 @ 10:54:48

Ben Ramsey has a post to his site sharing the process he's worked up to deploy PHP applications on AWS Codebuild, a new service from Amazon Web Services that fills the niche for an easy to spin up and use build server.

The main highlight of re:Invent is always the keynotes and the new services and features announcements they make during the keynotes. One of the new services caught my attention, and I decided to give it a try. That service is AWS CodeBuild.

CodeBuild is designed to be used as part of the AWS CodePipeline, but it may also be used by itself. [...] Out of the box, CodeBuild provides some managed images that you may use to build your projects. These include environments for Android, Java, Python, Ruby, Golang, and Node.js. PHP is missing from this list, but since you’re able to use other images, I decided to see how easy it is to get up and running on CodeBuild with a PHP project. I chose to try out my ramsey/uuid library for a simple test.

He walks you through the creation of a new CodeBuild instance (complete with screenshots of the UI) and how to configure your project, explaining each of the settings as he goes. He includes the full build command he's using for the library running tests, a lint check and codesniffer checks for formatting. He shows how to get the project to build and what the UI will show when the build is successful (all green).

tagged: project aws codebuild pipeline library tutorial setup build server amazon

Link: https://benramsey.com/blog/2016/12/aws-codebuild-php/

TutsPlus.com:
Building Your Startup: Issue Tracking and Feature Planning
Dec 02, 2016 @ 12:56:23

TutsPlus.com has continued their "Building Your Startup with PHP" series today with this latest tutorial covering the creation of an issue tracking and feature planning process with the help of the Anana service.

Even for a one-person startup, it helps to have more than a spreadsheet (or paper) to track issues, ideas, and bugs. A few years ago, I'd used Lighthouse for my grant-funded NewsCloud Community Starter Project. Last year, I'd been introduced to Asana during a consulting gig.

[...] Eventually, I found my way and discovered the tool works well whether you're working with a variety of people or just solo. In today's episode, I'll walk you through how I began using Asana for Meeting Planner. I use Asana not only to track issues but to organize them and plan for the future. I also use it to track and process bugs.

He walks you through getting started with the service (they have a free tier) and how to set up your first project. He includes examples of task creation, tagging tasks and tracking bugs right inside the service. He then uses it to create a "release plan" for the next version of the Meeting Planner application. He wraps up the post talking about what's next on his side for the Planner application and its funding goals.

tagged: build startup series meetingplanner issue tracking feature planning tutorial

Link: https://code.tutsplus.com/tutorials/building-your-startup-issue-tracking-and-feature-planning--cms-26722

MyBuilder Tech Blog:
Managing Background Processes within Symfony
Dec 02, 2016 @ 11:19:47

Edd Mann has written up a tutorial for the MyBuilder.com Tech blog about managing background processes in a Symfony application with the help of Supervisor.

When a web application reaches a sufficiently large size, it can become infeasible to perform all actions required within a single web request/response life-cycle. You may find yourself wishing to for example - batch up and send queued emails at particular intervals, or process payments asynchronous to the point in-time the user made the initial request. In this post I would like to discuss our changing use of background processes (both time-dependent and continuous) due to increasing throughput demands.

He starts out with the first approach most applications take when needing to run automated, asynchronous processes - cron. Using it and a custom bundle they created for it, Edd shows how to directly integrate the cron timing of commands into the class attributes. However, after a while the system grew and it needed something a bit more powerful than cron, something that could correctly handle long running processes. Ultimately they decided on Supervisor, a processes manager and control system that makes managing these processes simpler. He talks about the transition they made from cron over to Supervisor (safely) and how they integrated the signaling functionality Supervisor allows into their application.

tagged: symfony background process manage cron supervisor tutorial bundle

Link: http://tech.mybuilder.com/managing-background-processes-within-symfony/

TutsPlus.com:
Object-Oriented Autoloading in WordPress, Part 3
Dec 01, 2016 @ 11:15:35

TutsPlus.com has continued their series covering object-oriented development practices in WordPress (plugins) with this third tutorial. In previous parts they set up the environment and introduced some of the basic concepts of OOP programming and getting the first classes and files defined.

In the last tutorial, we reviewed the original state of our autoloader and then went through a process of object-oriented analysis and design. The purpose of doing this is so that we can tie together everything that we've covered in this series and the introductory series.

Secondly, the purpose of doing this in its own tutorial is so we can spend the rest of this time walking through our class, seeing how each part fits together, implementing it in our plugin, and then seeing how applying object-oriented programming and the single responsibility principle can lead to a more focused, maintainable solution.

They start with a brief review of what they've covered so far and begin to build on the changes suggested in the previous part of the series. They've already broken it down into the different functional classes (according to the single-responsibility principle) and take the next step of including them and calling some example code to prove all is working as expected.

tagged: oop wordpress tutorial series objectoriented programming plugin part3

Link: https://code.tutsplus.com/tutorials/object-oriented-autoloading-in-wordpress-part-3--cms-27515

SitePoint PHP Blog:
Event Sourcing in a Pinch
Nov 30, 2016 @ 10:56:26

Christopher Pitt is back with a new tutorial on the SitePoint PHP blog talking about event sourcing in PHP including a brief explanation about what it is and how it can be useful in your PHP application.

Let’s talk about Event Sourcing. Perhaps you’ve heard of it, but haven’t found the time to attend a conference talk or read one of the older, larger books which describe it. It’s one of those topics I wish I’d known about sooner, and today I’m going to describe it to you in a way that I understand it.

Christopher then gets into some of the basic concepts behind event sourcing, a part of Domain Driven Design, and the difference between storing state and storing behavior. With this outlined he gets into the creation of the actual event handlers with examples from a retail application (orders, outlets, stock, pricing, etc). He includes the code for several simple events, a method for recoding them in your database and some helper functions to translate the event to the SQL required for the insert operation. He then links these with the event classes and putting them to use, executing them and getting the results back via a sort of "layer" between the fetch and the response.

tagged: eventsourcing tutorial introduction example domaindrivendesign

Link: https://www.sitepoint.com/event-sourcing-in-a-pinch/

QaFoo Blog:
Using Traits With PHPUnit
Nov 29, 2016 @ 12:26:19

The QaFoo site has a new post showing an interesting practice that could be used in your PHPUnit tests to provide additional functionality without the need for complicated inheritance - the use of traits.

As we already wrote that "Code Reuse By Inheritance" has lots of problems and we consider it a code smell. You should always aim to use Dependency Injection, most likely Constructor Injection. But with test cases in PHPUnit we cannot do this because we have no control about how and when our test cases are created. There are a similar problem in other frameworks, like we discussed in "Object Lifecycle Control". We also blogged about traits as a Code Smell, but let me show and explain why they might be fine to use in your test cases.

They provide an example of where the use of traits might be acceptable starting with a simple test case to check the login behavior with an invalid password. This uses an "is a" inheritance relationship with a parent test class with setUp/tearDown method. This refactored a bit to make use of traits to provide common login functionality based on methods in a trait. The post wraps up talking about traits as a "code smell" despite them seemingly making the test code cleaner, mostly that it limits the ability to change functionality by simply changing the associated code.

tagged: traits phpunit tests code smell example tutorial

Link: https://qafoo.com/blog/092_using_traits_with_phpunit.html

SitePoint PHP Blog:
How to Properly Deploy Web Apps via SFTP with Git
Nov 29, 2016 @ 11:53:49

On the SitePoint PHP blog there's a new tutorial posted showing you how to properly deploy applications with SFTP and Git. In their examples they build a PHP-based deployment process that uses a few handy packages to make the flow simpler than a set of manual commands.

Uploading files is an integral aspect of any deployment process, and the underlying implementation can vary depending on the type of your server.

[...] The PHPSECLIB (PHP Secure Communications Library) package has an awesome API for routine SFTP tasks: it uses some optional PHP extensions if they’re available, and falls back on an internal PHP implementation otherwise. You don’t need any additional PHP extension to use this package, the default extensions that are packaged with PHP will do. In this article, we will first cover various features of PHPSECLIB – SFTP, including but not limited to uploading or deleting files. Then, we will take a look at how we can use Git in combination with this library to automate our SFTP deployment process.

They start with a quick command (Composer) to get the phpseclib library installed but then quickly move into using it and some SSH keys to:

  • authenticate to the server with public/private keys
  • uploading a sample file
  • automating the deployment with Git, pushing only changed files from a local git repo
  • getting the contents of a specific commit
  • the actual push of the files via SFTP

There's also a few other helpful hints included showing how to manage permissions on the remote server, execute remote commands and downloading files. The post ends with links to other similar tools if you're interested in more complete approaches.

tagged: deploy application sftp git deployment tutorial phpseclib example

Link: https://www.sitepoint.com/how-to-properly-deploy-web-apps-via-sftp-with-git/

Master Zend Framework:
The Composer Command-Line Essentials
Nov 29, 2016 @ 10:15:52

The Master Zend Framework site has posted a tutorial that seeks to help you get the most out of Composer on the command line with some essential tips beyond just he basics.

I know that a series on Composer might seem odd. But, as Composer’s been a part of PHP for so long now, I feel that it’s something which most of us take for granted. It’s revolutionised the PHP landscape, making it easier than ever before to build great software in PHP. But do we really know how to get the most out of it. For that reason, I’ve created this series, so that you level up your skills and really get the most from it.

In part one of this series, I’m going to take you through Composer’s command-line. I’ve cherry-picked a key subset of the command-line options, and focused in on key switches, so that you can do more than you already can.

He skips over the basic "require", "install" and "update" handling covered in many other tutorials and instead covers:

  • project creation
  • the "show" command to list installed packages
  • "remove" to drop a package from the current dependencies
  • using "depends" to see package dependencies
  • finding outdates packages with (appropriately) the "outdated" command
  • seeing suggested packages with "suggest"

For each item on the list there's an example of the command, what kind of options is allows and, for some, the output generated as a result.

tagged: composer command line advanced commands tutorial

Link: http://www.masterzendframework.com/series/tooling/composer/command-line-essentials/

MyBuilder Tech Blog:
Using Constraint-based Ordering in PHP
Nov 28, 2016 @ 11:09:18

On the MyBuilder.com Tech blog they've posted a tutorial from Edd Mann looking at the use of constraint-based ordering in PHP applications.

An interesting problem arose last week when we wished to generate a listing of recently completed jobs (along with their shortlist fees). Upon review of some earlier attempts, we did not like the aesthetics present when many of a particular shortlist fee were clustered together (i.e. two or more adjacent jobs with the same shortlist fee). What we were instead looking for was to create a constraint-based ordering that when applied to the recently completed jobs, would give an even distribution of shortlist fees (data-set permitting).

Initially he tried a "low-high" ordering method based on their "fee" value. Instead, to make the solution more "random" he reframed the need and broke it down into three separate actions: sort, partition and interleave. As PHP only has one of those, he came up with his own solutions for the other two (code included). He explains briefly how it all works together and what kind of benefits it has over the low-high solution originally created.

tagged: tutorial constraint based ordering example partition interleave

Link: http://tech.mybuilder.com/using-constraint-based-ordering-in-php/