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

Stefan Koopmanschap:
Sculpin and Docker
Mar 22, 2017 @ 12:49:05

Stefan Koopmanschap has written up a tutorial on his site introducing the use of Docker and Sculpin to create an easily reproducible and manageable blogging setup.

I've been running this blog on Sculpin for quite a while now, and I'm quite happy with how that works. We've been in a process of migrating some of our websites off a standard VPS towards a setup with Docker, Gitlab CI and Rancher. I've now migrated some websites, which is relatively easy, but most of those sites were dynamic PHP websites. Migrating a site that generates static HTML and running that is a slightly different thing. Here's how I ended up doing it.

First he covers his old setup - essentially the manual run of a shell command to generate the latest version of a the static Sculpin site. He decided to update the process and help makes things more automatic using Docker and a Gitlab pipeline flow. He then documents his attempts and configuration options as he built up the Docker configuration he wanted. This ultimately resulted in a Docker setup that installed PHP and Nginx to serve up the site, Composer to load in the required dependencies (like Sculpin) and the commands to "deploy" the latest version of the site publicly.

tagged: sculpin docker setup configuration tutorial dockerfile php7

Link: https://leftontheweb.com/blog/2017/03/18/sculpin-and-docker/

Simon Holywell:
PHP and immutability
Mar 22, 2017 @ 11:21:37

In a recent post to his site Simon Holywell covers immutability in PHP. PHP, by default, uses weak typing and doesn't support much in the way of immutability but Simon shows you a few ways you can get around this and make immutable objects you can use and extend.

Being a weakly typed dynamic language, PHP has not really had the concept of immutability built into it. We’ve seen the venerable define() and CONSTANTS of course, but they’re limited. Whilst PHP does ship with an immutable class as part of it’s standard library, DateTimeImmutable, there is no immediately obvious method to create custom immutable objects.

[...] It is possible to write your own immutables using some simple and sneaky PHP techniques though. We’re going to use a simplistic data requirement to make the examples in this article easier to follow. I’ll be using professional skateboarders and the tricks that they brought to the world.

He starts the article talking about immutability and how it relates back to the current (as of PHP 7) values supported in constants - scalars and arrays (no objects). He then starts on the code to create the base Immutable class that sets its values via the constructor. He then points out some of the common "work arounds" people use when trying to work with immutable objects and some techniques to help prevent it: the use of final, a "flag" preventing another constructor call, etc.

tagged: immutable tutorial technique php7 constant

Link: https://www.simonholywell.com/post/2017/03/php-and-immutability/

QaFoo:
How to Perform Extract Service Refactoring When You Don't Have Tests
Mar 22, 2017 @ 10:42:39

On the QaFoo blog they've posted an article sharing advice about refactoring to extract logic to services when there's no testing to cover the code.

When you are refactoring in a legacy codebase, the goal is often to reduce complexity or separate concerns from classes, methods and functions that do too much work themselves. Primary candidates for refactoring are often controller classes or use-case oriented service classes (such as a UserService).

Extracting new service classes is one popular refactoring to separate concerns, but without tests it is dangerous because there are many ways to break your original code. This post presents a list of steps and checklists to perform extract service when you don't have tests or only minimal test coverage. It is not 100% safe but it provides small baby-steps that can be applied and immediately verified.

The article talks about some of the primary risks when performing this kind of refactoring and how their extract method recommendations could case some of those issues. The tutorial then breaks down the process into the small steps:

  • Step 1: Create Class and Copy Method
  • Step 2: Fix Visibility, Namespace, Use and Autoloading
  • Step 3: Check for Instance Variable Usage
  • Step 4: Use New Class Inline
  • Step 5: Inline Method
  • Step 6: Move Instantiation into Constructor or Setter
  • Step 7: Cleanup Dependency Injection

While that seems like a lot of steps to take, they're all pretty small. They include a series of code snippets giving you an example to work from, making these small steps to refactor current functionality into a Solr service class.

tagged: tutorial refactor extract service tutorial unittest example code

Link: https://qafoo.com/blog/099_extract_service_class.html

Zend Framework Blog:
Create ZPKs the Easy Way
Mar 22, 2017 @ 09:05:17

On the Zend Framework blog Enrico Zimuel has posted a tutorial showing you how to easily create ZPKs and package up your application for deployment on Zend Server.

Zend Server provides the ability to deploy applications to a single server or cluster of servers via the ZPK package format. We have offered zf-deploy for creating these packages from Zend Framework and Apigility applications, but how can you create these for Expressive, or, really, any PHP application?

They start by listing out some of the requirements you'll need to get started (the zip binary, Composer, etc). The tutorial then walks you through the setup including the contents of the .htaccess and deployment.xmlconfiguration files. It then walks through the installation of dependencies and actually creating the ZFK (via the zip binary). It wraps up with a simple example of the creation of a ZPK containing a single index.php file.

tagged: zendframework zendserver zpk zip package deployment tutorial

Link: https://framework.zend.com/blog/2017-03-21-create-zpks-the-easy-way.html

Community News:
Recent posts from PHP Quickfix (03.22.2017)
Mar 22, 2017 @ 08:05:01

Recent posts from the PHP Quickfix site:

tagged:

Link:

Leonid Mamchenkov:
Getting started with workflows in PHP
Mar 21, 2017 @ 12:12:24

Leonid Mamchenkov has put together a post for those out there trying to get started with workflows in PHP and offers some tips from his own experience.

For a large project at work, we need to integrate or develop a workflow engine. I worked a little bit with workflow engines in the past, but the subject is way to big and complex for me to claim any expertise in it.

So, I am looking at what’s available these days and what are our options. This post is a collection of initial links and thoughts, and it’s goal is mostly to document my research process and findings, and not to provide any answers or solutions yet.

He starts off by defining the requirements of the system he's looking for, both on the technology side and the functional side. He outlines his expected flow and then links to some other resources he found to help define common terminology and some of the standards he found. He found the BPMN v2.0 and tracked down several PHP packages that implement that workflow structure (all linked as well).

tagged: workflow gettingstarted introduction concepts packages

Link: http://mamchenkov.net/wordpress/2017/03/20/getting-started-with-workflows-in-php/

Laravel News:
Five Minutes with Justin Jackson
Mar 21, 2017 @ 11:05:28

The Laravel News site has posted an interview with Justin Jackson, one of the speakers at the upcoming Laracon US conference and creator of Marketing for Developers (among other things).

Laracon US is still a few months away and this year it has an awesome line up of speakers. One of the new faces is Justin Jackson, who is what you could call a habitual maker. He launches more products than I have ideas.

Justin is a former Product Manager and has now transitioned into a full-time product person. He builds products such as Marketing for Developers, runs the MegaMaker podcast, and sells a book named Jolt! What follows is a quick interview with Justin to share some insights into making products and what to expect during his Laracon talk.

In the interview Justin answers questions about his background, his talk at Laracon US and launching products.

tagged: interview fiveminutes justinjackson laraconus speaker marketing

Link: https://laravel-news.com/justin-jackson

Quora.com:
What are some things you wish you knew when you started programming?
Mar 21, 2017 @ 10:24:44

Leonid Mamchenkov has linked over to a great thread over on Quora that asks the question "[What are some things you wish you knew when you started programming?

](https://www.quora.com/What-are-some-things-you-wish-you-knew-when-you-started-programming)?"

The post is originally from Ken Mazaika, CTO, Co-founder & Mentor @ thefirehoseproject.com but it has expanded way beyond his original list of 27 things. There's comments sharing everything from personal experiences out to their own lists of things they wish they knew. Topics mentioned include:

  • the "cognitive burden"
  • the importance of getting away from the screen sometimes
  • the value in listening, not just hearing, your colleagues
  • thinking about security at all times
  • learning the "why" of coding, not just the "how"

There's a lot more in this post so get over and start reading. There tips in here for everyone, both those new to programming and those that have been doing it for years.

tagged: wish you knew programming opinion experience quora

Link: https://www.quora.com/What-are-some-things-you-wish-you-knew-when-you-started-programming

Sameer Borate:
Accessing Google Page Insights in PHP
Mar 21, 2017 @ 09:45:12

On his site today Sameer Borate shares a tutorial showing you how to access Google Insights data via your PHP application with the help of the dsentker/phpinsights package.

Google Page Insights is a required tool to have when analyzing the speed and usability of your site. As you may know these metrics influence how google ranks your page in search results. If you frequently make changes to your web site designs than it becomes mandatory to check the metrics after each change to make sure that the design changes has not affected the score in any negative way. If you have many pages to test than manual testing can quickly become cumbersome.

Thankfully there are libraries that you can use to automate this process. Once such is given in this post which allows you to get Google Page Insight metrics using PHP.

He then walks you through the installation of the package (via Composer) and how to use it, along with your Google API key, to fetch the information for a given URL. You can get information for different environments (desktop vs mobile) and even a screenshot of the page that's under test. He ends the post with a helpful hint for those that might get a certificate error when making the request and how to fix it.

tagged: google insights data tutorial package install usage

Link: http://www.codediesel.com/api/accessing-google-page-insights-php/

Community News:
Latest PECL Releases (03.21.2017)
Mar 21, 2017 @ 08:05:01

Latest PECL Releases:

  • tcpwrap 1.2.0
    Add compatibility with recent PHP versions

  • gRPC 1.2.0
    - Added arg info macros #9751 - Updated codegen to be consistent with protobuf #9492
  • amqp 1.9.0
    * AMQP types are now better supported through value objects (see #271, #269, #265) (Bogdan Padalko, Lars Strojny)

    For a complete list of changes see: https://github.com/pdezwart/php-amqp/compare/v1.8.0...v1.9.0

  • mongodb 1.2.8
    ** Improvement * [PHPC-936] - Define PHP_MONGODB_VERSION constant for Pickle compatibility
  • hprose 1.6.6
    Fixed object unserialize on PHP 7.1.
  • swoole 2.0.7
    - Added Coroutine::create function, allows user to create coroutine - Fixed HttpClient crash
  • v8js 1.3.6
    Bugfixes - fix compilation with GCC7 (include necessary headers) - fix build with recent V8 5.9 versions (libv8_libplatform not found) - adapt exception_start_column.phpt test to changed output of recent V8 5.9 versions - fix compilation with PHP 7.1.3

    Refactorings

    • drop TSRM stuff unneeded since PHP 7
    • remove unused variables
    • make memory_limit a size_t internally (and throw if negative values are provided on PHP interface)
  • cassandra 1.3.0
    # 1.3.0

    Features:

    • Added support for the duration type
    • Added support to pass a query string directly to Session::execute() and Session::executeAsync()
    • ExecutionOptions has been deprecated in favor of using an array

    Bug Fixes:

    • [PHP-86] Decimal __toString method
    • [PHP-109] Cassandra solr_query not working after upgrading to DSE 5
    • [PHP-114] pecl install compiler output is dominated by C90 warnings
    • [PHP-119] Driver crashes upon getting type of column
    • [PHP-143] Memory leak in FutureSession
    • [PHP-144] Fix persistent sessions reference counting issue
    • [PHP-147] Unable to create Bigint with PHP_INT_MIN
  • swoole 1.9.8
    - Fix some compilation errors
  • swoole 1.9.7
    - Added support for systemd.socket - Added swoolehttp2client - Added client support for http-proxy - Added the swoole_process::close parameter, allowing only one of the pipes to be closed - Fixed MySQL client crash when the low version gcc is compiled - Fixed the crash in the BASE mode shutdown - Fixed openssl-1.1 configuration detection error problem - Fixed open_eof_split after enabling BASE mode to turn off connections in the onReceive callback function - Fixed the problem with the Redis Server :: format function SET and MAP formatting errors - Fixed a problem that caused a crash when a string type variable was passed directly when swoole.fast_serialize was enabled - Update The reactorId variable in the onClose callback is set to -1 when the server actively shuts down the connection
  • mongodb 1.2.7
    ** Bug * [PHPC-500] - Resolve PHP 7 memory leaks * [PHPC-931] - php_phongo_pclient_t is leaked during MSHUTDOWN * [PHPC-933] - Unnecessary zend_string_release() in phongo_zval_to_bson() for PHP 7

    ** Task * [PHPC-411] - Drop system.profile collection before tests

  • yar 2.0.2
    - Fixed issue #98 (Memeory exhuasted while using with Yaf)
tagged:

Link: