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

Community News:
Latest PECL Releases (06.19.2018)
Jun 19, 2018 @ 08:05:01

Latest PECL Releases:

  • ibm_db2 2.0.6
    Fixed crash while in windows.

  • swoole 4.0.0
    - Using c stackful coroutine - Allow to create server in multiple processes - Fixed issue where http2 server could not send more than 16K data to Chrome browser client - Added Channel->peek method for peeping data - Fixed issue where Server->pause/resume could not be used under SWOOLE_PROCESS - Removed Linux AIO and use thread pool for asynchronous file IO anyway - Added MySQL stored procedure supports
tagged:

Link:

Ben Sampson:
Creating a decent Laravel deploy script
Jun 15, 2018 @ 13:45:38

Ben Sampson has posted a quick guide on his site sharing a deployment script for Laravel applications he's found useful.

A good deploy script can save you time and speed up your application, and it only takes a few minutes to set one up.

I have a standard deploy script which I use for almost all of my projects, which I'm going to break down and share with you.

Note: This article assumes that you're using Laravel Forge. If you're not, many of the settings will be applicable, but the setup steps may be a bit different.

He starts with a brief description of what a deployment script is and goes through the functionality he has included in his:

  • switching the site to maintenance mode
  • clearing caches
  • clearing and optimizing routes
  • clearing and optimizing the configuration
  • clearing expired password reset tokens
  • compiling front-end assets

He puts it all together into a single file that's then included in the Forge deployment process. He doesn't provide other instruction as to how to use this script with another deployment method but it can potentially be used anywhere a bash script could.

tagged: laravel deployment script steps laravelforge tutorial

Link: https://sampo.co.uk/blog/creating-a-decent-laravel-deploy-script

SitePoint PHP Blog:
Apache vs Nginx Performance: Optimization Techniques
Jun 15, 2018 @ 12:22:11

On the SitePoint PHP blog they've posted a tutorial from author Tonino Jankov sharing some techniques you can use to increase the performance of Apache and Nginx when serving up your web applications.

The article starts with some of the basics, introducing both the software and some of the concepts around their use and evaluation:

  • an introduction to Apache and Nginx
  • hardware considerations
  • monitoring
  • testing the systems (benchmarking)

It then starts on the tuning tips, one section for each of the web servers. For Apache it covers changes for the mpm modules, disabling htaccess and browser cache control with mod_expires. On the Nginx side, they mention changing the number of workers created, tuning the keepalive timout and setting up server-side caching.

tagged: apache nginx performance optimize tip tutorial configuration

Link: https://www.sitepoint.com/apache-vs-nginx-performance-optimization-techniques/

php[architect]:
Self-Host Your Team’s Git With Gitolite
Jun 15, 2018 @ 11:17:12

On the php[architect] site they've shared a post from their most recent issue (June 2018 - Command and Control) from author Gabriel Zerbib covering self-hosting Git with Gitolite.

If you wish to set up a private Git server for your personal, work, or team projects, but favor free software and simple architecture, or don’t want a service hosted by a third party, then Gitolite is the solution for you.

The article starts with a brief history of Git and a listing of some of the options for hosting private Git repositories. It then gets into talking about Gitolite, a "collection of Perl scripts, wisely arranged to allow easy management of Git repositories served over the SSH protocol." He talks through some of the features that come along with the tool and how to get it installed. With that setup, he shows how to use it as a Git hosting platform, how to configure repositories, create and configure users, and perform backups. The post ends with some helpful troubleshooting tips and a look at Gitolite's hook system.

tagged: gitolite phparch june2018 article git hosting tutorial introduction

Link: https://www.phparch.com/2018/06/self-host-your-teams-git-with-gitolite/

Laravel News:
PHP 7.3: Trailing Commas in Function Calls
Jun 15, 2018 @ 10:46:51

In a post in the Laravel News site, they quickly cover one of the many changes coming with the next jump in versions of the PHP language (v7.3): trailing commas in function calls.

Well PHP 7.3 won’t have arrow functions (that would be dreamy). However, trailing commas in function calls is an excellent addition coming to PHP 7.3.

In PHP 7.3, trailing commas in function calls will be valid syntax. That is to say, you can use trailing commas when calling functions, but not defining them.

They then include two places where these trailing commas could be useful: in the use of variadic functions and in PHP array definitions. The remainder of the post shows the concept of "trailing commas" in other languages including Javascript, Python, and Haskell. The first alpha release of PHP 7.3 has been released if you'd like to try this out with your own code.

tagged: trailing comma function call php73 feature alpha tutorial

Link: https://laravel-news.com/php-trailing-commas-functions

Tomas Votruba:
Collector Pattern for Dummies
Jun 15, 2018 @ 09:03:13

In a new post to his site Tomas Votruba comes back to a topic he posted about previously - the collector pattern - and provides a simpler, more introductory look at the pattern and what it's useful for.

I wrote Why is Collector Pattern so Awesome a while ago, but I got feeling and feedback that it's way too complicated.

The pattern itself is simple but put in framework context, it might be too confusing to understand. That's why we look on collector pattern in minimalistic plain PHP way today.

He uses a calculator example help explain the use of the pattern, starting with a simple class that calculates the price of a product + VAT. He then shows a few examples of how it could grow over time as business requirements change. He refactors the class to make it easier to add in these one-off changes by setting them all as "calculators' in a calculator collection. He provides the code examples for this refactor and an example of it in use.

tagged: collector pattern introduction calculator tutorial

Link: https://www.tomasvotruba.cz/blog/2018/06/14/collector-pattern-for-dummies/


Site News:
Blast from the Past - One Year Ago in PHP (06.14.2018)
Jun 14, 2018 @ 08:05:02

Here's what was popular in the PHP community one year ago today:

tagged:

Link:

php[architect]:
June 2018 Issue Release - Command and Control
Jun 13, 2018 @ 13:08:27

php[architect] magazine has announced the release of their June 2018 issue - Command and Control. This issue includes articles like:

  • "Domain-Driven Architecture With Commands and Events" by Barney Hanlon
  • "Pro Parsing Techniques With PHP, Part One: Simplifying Your Parsing Strategy" by Michael Schrenk
  • "Design Is for Designers" by Steve Bennett
  • "Self-Host Your Team’s Git With Gitolite" by Gabriel Zerbib

The usual columns are also back sharing tips for development leads, security, going "beyond PHP" and building APIs. You can check out the articles in this month's issue and pick up a copy on the php[architect] site. If you're interested to "try before you buy", check out this month's free article about Git and Gitolite.

tagged: issue release phparchitect commandandcontrol june2018

Link: https://www.phparch.com/magazine/2018-2/june/

Tomas Votruba:
How to Turn Mocks from Nightmare to Solid Kiss Tests
Jun 13, 2018 @ 12:36:48

In a new post to his site Tomas Votruba shows you how to make your unit test mocks better with an easier and clearer way to use them. This simplification makes use of something PHP itself is already able to do: create anonymous classes.

At the time being, there is only 1 post about anonymous classes in tests (thanks to Matthieu!). Compared to that, there are many PHP tool made just for mocking: Prophecy, Mockery, PHPUnit native mocks, Mockista and so on. If you're a developer who uses one of them, knows that he needs to add proper annotations to make autocomplete work, has the PHPStom plugin that fixes bugs in this autocomplete and it works well for you, just stop reading.

This post is for developers who struggle with mocking and have a feeling, that they're doing something wrong.

He starts with an example of a test that creates a mock for an external request to the Heroku service using PHPUnit's mocking tools. He points out that this requires extra knowledge of the mocking methods and functionality to accomplish, potentially making it difficult to understand for those new to the tool. He then shares a refactor of the same test, this time making use of an anonymous class to mock out the needed findByCategoryId method and return a response. He ends the post pointing out that, as a side effect of this refactoring (and other interface refactoring) you'll create more SOLID code and it can help make it easier to maintain in the future.

tagged: tutorial mock unittest test anonymous class tool

Link: https://www.tomasvotruba.cz/blog/2018/06/11/how-to-turn-mocks-from-nightmare-to-solid-kiss-tests/