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

Matthew Weier O'Phinney:
On PSR7 and HTTP Headers
Jul 29, 2015 @ 09:47:59

Matthew Weier O'Phinney has a new post to his site talking about PSR-7 and HTTP headers and how they (headers) are handled in the structure of this PHP-FIG specification.

Yesterday, a question tagged #psr7 on Twitter caught my eye: "When I call $request->getHeader('Accept') for example, I was expected that I'll get [an array] but, in reality I got [a string]. Is this correct?" In this post, I'll explain why the behavior observed is correct, as well as shed a light on a few details of header handling in PSR-7.

He talks about the planning that went into PSR-7 and how they had to work around some of the "flexibility" (quirks) in the HTTP specification. This was especially true when it came to repeated headers. He also walks through their thoughts on multiple header handling and that custom header values are allowed. Because of these two things, they decided to treat all headers as collections and, despite there being separators already in the values. Instead they collected headers of the same types into these collections, some containing only one value while others could contain multiple. Back to the question - this explains why the "Accept" header they desired was still in its comma-separated form and not split into the array they expected.

The [...] example provides another good lesson: Complex values should have dedicated parsers. PSR-7 literally only deals with the low-level details of an HTTP message, and provides no interpretation of it. Some header values, such as the Accept header, require dedicated parsers to make sense of the value.
tagged: psr7 http header collection separator multiple single

Link: https://mwop.net/blog/2015-07-28-on-psr7-headers.html

SitePoint PHP Blog:
Multiple Editors per Node in Drupal 7
Jun 11, 2015 @ 09:57:49

The SitePoint PHP blog has posted a new Drupal tutorial about allowing multiple editors to work on the same node of content.

have encountered a practical use case where the default configuration options are not enough. Namely, if you need to have multiple users with access to edit a particular node of a given type but without them necessarily having access to edit others of the same type. In other words, the next great article should be editable by Laura and Glenn but not by their colleagues. However, out of the box, users of a particular role can be masters either of their own content or of all content of a certain type. So this is not immediately possible. In this article I am going to show you my solution to this problem in the form of a simple custom module called editor_list.

He walks you through the process, first creating the .info file needed to define the module and the changes needed for the .module file. He creates a few helper functions to get the editor listing for a node and its matching access rules. With the module created he then gets into building the fields, again making helper methods to get the editors for the fields. Finally he "tidies up" and adds an "Authored on" section to the node editor with a helper function to receive and handle the results of this field when the form is submitted.

tagged: multiple editor drupal node field tutorial

Link: http://www.sitepoint.com/multiple-editors-per-node-drupal-7/

PHP 5.6.8, 5.5.24 & 5.4.40 Released (Security Fixes)
Apr 17, 2015 @ 09:38:18

The PHP development group has released several different versions of PHP for the 5.5.x, 5.6.x and 5.4.x series with a long list of security issues fixed in each one (fourteen in total):

The PHP development team announces the immediate availability of PHP [5.4.40, 5.6.8, 5.5.24]. 14 security-related bugs were fixed in this release, including CVE-2014-9709, CVE-2015-2301, CVE-2015-2783, CVE-2015-1352. All PHP 5.4 users are encouraged to upgrade to this version.

Other items were fixed besides the security issues, so check out the Changelog to see those few other fixes. It's highly recommended that you update your installations to these latest versions. You can grab the latest either from the downloads page (source) or Windows users can go to winodws.php.net.

tagged: language release multiple security fix changelog upgrade

Link: http://php.net/archive/2015.php#id2015-04-16-3

Building With the Twitter API: Tweet Storms
Jan 07, 2015 @ 12:49:22

NetTuts.com has posted the second part of their series about creating a Twitter client on top of the Yii framework. In this new tutorial they focus on "tweet storms", the use of a series of tweets to share a thought rather than just cramming it into one.

In April, investor and Netscape founder Marc Andreessen began expanding on the natural 140 character limits of Twitter by publishing his thoughts in sequences of tweets, which some have dubbed tweet storms. [...] A few services arose to make it easier for mere mortals like ourselves to publish tweet storms but they seemed a bit unreliable and inconsistent. I decided to build the feature myself and I think there's value in doing this with your own app.

He outlines the features that the "tweet storm" feature needs to support and the database models/migrations that you'll need to store the related data. He uses Yii's generators to create the needed skeleton classes for the models and controllers. He moves on to the code needed to handle the group tweets management and to compose the tweets that will make up the "storm". Finally, he includes the code you'll need to create the publishing feature, pushing it into both the models/database and out to the Twitter API. You can then use the "OEmbed" information provided by Twitter to view the series of tweets via another simple page (code included here too).

tagged: tutorial twitter storm multiple tweet yii framework series part2

Link: http://code.tutsplus.com/tutorials/building-with-the-twitter-api-tweet-storms--cms-22459

SitePoint PHP Blog:
How to Run Multiple Versions of PHP on One Server
Nov 07, 2014 @ 10:54:27

The SitePoint PHP blog has a new tutorial by Thien Tran Duy showing you how to run multiple versions of PHP all on the same server. The key is in using a few custom configuration options (you'll be compiling PHP manually for this) to place the different versions in different locations.

In this particular post, we’ll demo a solution to install multiple versions of Phalcon and PHP and run them on a single web server. PHP 5.5.x and 5.6.x will be used here, but you can replace them with other versions. Any servers that support PHP-FPM should be enough but we recommend using Nginx. The environment used in this tutorial is Fedora OS – a Linux system, but the instructions are almost identical for any other *nix OS.

The tutorial also includes the installation of a few other PHP extensions including APC caching, memcache and ioncube. He walks you through the installation of Nginx first to get the web server up and running. Then he starts in on the PHP installs and the requirements to ensure you have to be able to compile from the PHP source. He shows how to pull the different versions of PHP down (5.3, 5.4, 5.6 and master) from the GitHub repository and execute the "buildconf" to make the configure script. He includes the example configuration command with options, ensuring it will work with PHP-FPM and the Nginx server. He then reproduces the process, making slight changes, for the other versions of PHP. Finally, he shows the installation of the two different versions of Phalcon and configuring it to all work with the installed web server.

tagged: multiple version one server language tutorial phpfpm nginx

Link: http://www.sitepoint.com/run-multiple-versions-php-one-server/

SitePoint PHP Blog:
How to Use PHPbrew and VirtPHP
Oct 06, 2014 @ 13:08:41

Phil Sturgeon has written up a new tutorial for the SitePoint PHP blog showing you how to use PHPbrew and VirtPHP to be able to work with more than one PHP version on the same system.

We’ve all been in the situation where we have one version installed. Maybe that version is whatever came installed on our operating system. Maybe it is a version bundled into MAMP/WAMP/XAMPP. How do you go about switching that PHP version? How do you switch to one version, then switch back again? How do you go about switching that version of PHP, but only for one single application on your computer? The Ruby and Python communities have had tools for dealing with this for years. PHP has them now too, but there was nowhere near enough fanfare.

He starts with PHPbrew and walks you through a basic install and configuration of a version of PHP 5.6.0. He shows how to add extension support and switch between the different PHP versions at will. Next comes the look at VirtPHP, a similar system that takes a little bit different approach. It creates "environments" that contain the PHP version to a bit more isolated setup. With an environment created, VirtPHP lets you install PECL extensions without changing anything globally. He ends the post with a comparison to how most developers (developing locally) handle their setup and mentions Vagrant, but notes that it may be a bit much for the solo developer.

tagged: virtphp phpbrew tutorial multiple version install configure

Link: http://www.sitepoint.com/use-phpbrew-virtphp/

Lorna Mitchell:
Running Multiple Versions of PHP
Aug 20, 2014 @ 09:28:57

In the latest post to her site Lorna Mitchell has posted a helpful hint on how you can run multiple versions of PHP at once, mostly how to get the latest version without messing up your current install.

When I advise people about upgrading their PHP version, I say things like "just run your test suite with the new version" "just grab the new version and try your site with the built-in webserver". A couple of people recently have asked for more detail on how to actually achieve these things so here's a quick primer on getting new PHP without touching anything to do with your existing PHP installation.

You'll need a bit of knowledge around compiling software to get the job done, so if you're only used to aptget-ing or yum-ing you might be a little lost. She does include all the commands you'll need including the special "prefix" flag on configure telling it to put PHP in a different location than normal. She also includes a brief test to ensure that it's all up and working (using the built-in web server).

tagged: multiple version language tutorial installation

Link: http://www.lornajane.net/posts/2014/running-multiple-versions-of-php

Loosely Coupled Podcast:
Episode 8: Do You Even Polyglot?
Aug 04, 2014 @ 09:05:30

The Loosely Coupled podcast has posted the eighth episode of their podcast (hosted by PHP community members Jeff Carouth and Matt Frost) asking "Do you even polyglot?"

In this episode Jeff and Matt talk about the idea of polyglotism, the benefits, practical advice about choosing which languages to learn and how to be successful while learning new languages. You should go out and find a new language and prepare to give it the time it deserves. It’s best to find a mentor or someone to help you and step out of your language or paradigm comfort zone.

They mention several other topics including Clojure, the splat operator and fellow community members Joel Clermont and Igor Wiedler. You can listen to this latest episode either through the in-page audio player or by downloading the mp3 directly.

tagged: looselycoupled podcast ep8 polyglot multiple language choice success

Link: http://looselycoupled.info/blog/2014/07/22/episode-8-do-you-even-polyglot/

Allan MacGregor:
Exploring Traits
Mar 17, 2014 @ 11:48:59

In his new post Allan MacGregor takes a look at a somewhat underused feature of PHP (since 5.4), traits. He talks about how they can help solve multiple inheritance issues and the power they can offer.

Languages like C++ or Python manage this problem by allowing inheritance from multiple classes, Ruby in the other hand uses Mixings to address this issue. Regardless of the technique the problem remains the same; Traits are another approach to this problem and are commonly used in the languages like Perl and Scala.

He includes an example of the standard PHP method for inheritance in classes via the normal "extends" handling. He refactors this into a setup using traits to "override" the single inheritance issues via a "Cat" trait included in the "Tiger" class providing the "roar" method inside the class context.

The best part about traits is that it makes sense from a structural point of view. [...] Traits are an incredible addition to the PHP language and we have only started to touch the surface.
tagged: traits introduction multiple inheritance

Link: http://coderoncode.com/2014/03/17/exploring-traits.html

Andreas Gohr:
Docker PHP Farm
Feb 03, 2014 @ 10:05:19

In his latest post Andreas Gohr shares a platform he's developed using docker to create a multi-PHP version instance that can run locally with just a few commands.

Yesterday I tried to fix a bug a user had reported in one of my DokuWiki plugins. Apparently it only occurred on PHP 5.2. Well, the last PHP 5.2 version was released in 2011 and no modern distribution has it anymore. So how do I test this easily? After a few failed attempts with finding a virtual machine image that would give me the needed PHP version I decided to come up with my own solution. And because I was curious - I decided to build it on docker.

He's already done the hard work for you and created the "phpfarm" project that's easy to pull in and use. He includes the two commands to get it downloaded and up and working and running PHP versions 5.2 through 5.5 on ports 8052 to 8055. If you're interested in seeing his Dockerfile, check it out on Github.

tagged: docker phpfarm version multiple container

Link: http://www.splitbrain.org/blog/2014-02/02-docker_phpfarm