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

Terry Chay:
Which has better packages, Python or PHP?
Sep 13, 2018 @ 10:27:50

Terry Chay has an interesting post on his site that wonders which language has better packages - PHP or Python?

It depends on the target utility. In the Python world, the most common package installer is pip; the PHP world didn’t settle on a dominant format/installation for packages until composer, and that was relatively recently (last 4 years).

[...] So which has better packages? The answer is it depends on the domain. In nearly any language you can find an adequate package for any of your needs, but overall you will find the packages are higher quality, more up-to-date, and sometimes just better overall in the domain the language seems to target well.

He starts off by talking some about PHP and Python's origins - PHP as a web-focused language and Python as more general purpose - and how this influenced their package implementations. He then shares his opinions on which kind of packages are a more natural fit for which languages:

  • for data science/AI/ML applications, Python
  • for DevOps, relying on other tools (Puppet/Chef/Ansible/etc) is better
  • For server-side web-based packages, I feel PHP and Composer [are the solution]

He also includes some thoughts about other languages - Ruby, Javascript, Go - and their own package managers.

tagged: package manager python comparison opinion usage

Link: http://terrychay.com/article/which-has-better-packages-python-or-php.shtml

Tomas Votruba:
Hidden Gems of PHP Packages: NetteUtils
Jul 31, 2018 @ 10:36:37

Tomas Votruba has a new post to his site sharing what he calls a "hidden gem" of a PHP package that he finds useful: the NetteUtils package. This is the first part of a series of posts dedicated to packages he finds helpful.

In this series, I will show you not-so-known PHP packages, that I happily use in my daily workflow. They're hard to describe in few words for their various features, but awesome and simple to use.

Today we start with NetteUtils package.

He starts with a few points about why he uses the library (including mentioning some specific functionality) and how to get it installed in your own application. He then goes through some example code showing the functionality he uses including the Strings and FileSystem classes.

tagged: hiddengem package netteutils detail install usage tutorial

Link: https://www.tomasvotruba.cz/blog/2018/07/30/hidden-gems-of-php-packages-nette-utils/

Exakat Blog:
The 100 PHP functions that you have to know
May 31, 2018 @ 09:54:33

On the Exakat blog they have a new post with the results from their evaluation of a wide range of PHP applications showing the Top 100 PHP functions in use.

Here is the top 100 PHP functions : it is the list of the most often used PHP native functions.

The functions are named, and ranked from 1 to 100. The other 4500 functions are not ranked now. The frequency column represents how often this function is used across PHP code : the reference corpus is a list of 1900 PHP open source projects. They were audited with Exakat static analysis engine, version 1.2.5. The average is the number of time a function is called within one project. Some function are used in isolation, and others are a staple.

The top 5 on the list are:

Each item on the list comes with "frequency" and "average" scores (that mostly relate directly). Check out the post for the full list and a list of some insights they worked up as they generated the listing.

tagged: top100 list function language ranking usage

Link: https://www.exakat.io/top-100-php-functions/

Exakat Blog:
PHP assertions and their usage
Jan 18, 2018 @ 11:16:58

On the Exakat blog there's a post that covers assertions in PHP, a built-in tool the language provides to help perform simple value based evaluation against certain criteria.

PHP has a clever native debugging tool : the PHP assertions. In a nutshell, assertions are a function call to assert(), that triggers an error when a condition is not satisfied.

[...] Unlike debugging conditions, the assert() syntax has to be read in a positive way. When the condition, aka as the first argument, is satisfied, all is fine, and process goes on; when the condition is not satisfied, then an error is triggered: the message of the error is the second argument.

The post then gets into more detail about the assertions, noting that the result has to be positive and that they can be somewhat configured (basically turned on/off and the error level can be adjusted). It also covers some examples of things to test with assertions, how they should be treated as debugging and to avoid using them on resources outside the code (like database connections).

tagged: assertion usage language native tutorial introduction

Link: https://www.exakat.io/php-assertions-usage/

Jordi Boggiano:
PHP Versions Stats - 2017.2 Edition
Nov 13, 2017 @ 11:51:01

Jordi Boggiano is back with the latest round of his PHP version statistics as gathered from the information provided by the Composer package management tool for PHP.

It's stats o'clock! See 2014, 2015, 2016.1, 2016.2 and 2017.1 for previous similar posts.

A quick note on methodology, because all these stats are imperfect as they just sample some subset of the PHP user base. I look in the packagist.org logs of the last month for Composer installs done by someone. Composer sends the PHP version it is running with in its User-Agent header, so I can use that to see which PHP versions people are using Composer with.

He then shares the results of the statistics including the total number of users for each version of the language and the difference in just the last 6-7 months. PHP 7.1 has pulled out as a front-runner with PHP 7.0 coming in closely after. He also shows some historical data showing the decline of the 5.x versions and the rise of 7.x versions over the past years. The post ends with information about the percentage of requirements in packages with 5.6 taking the lead but not by much.

tagged: composer language version usage statistics 2017

Link: https://seld.be/notes/php-versions-stats-2017-2-edition

Zend Framework Blog:
Protecting passwords with Argon2 in PHP 7.2
Aug 18, 2017 @ 11:12:01

On the Zend Framework blog today there's a new post from Enrico Zimuel showing you how you can use Argon2 password hashing in PHP applications (coming natively in PHP 7.2).

PHP 7.2 will be released later this year (2017). This version contains some interesting additions, including two new security features: support of the libsodium library.

With these new features, PHP is the first programming language to adopt modern cryptography in its standard library.

In this article, we demonstrate the usage of the Argon2 password hash algorithm.

He then walks you through the installation of the pre-release version of PHP 7.2 and the argon2 library to get the environment up and running. He briefly talks about what the Argon2 hashing algorithm is and how to use it directly in PHP via the password_hash function. He also mentions the password_get_info function and shows what the result of inspection on an Argon2 application contains.

tagged: password hash argon2 tutorial install usage

Link: https://framework.zend.com/blog/2017-08-17-php72-argon2-hash-password.html

Amazon Web Services:
PHP application logging with Amazon CloudWatch Logs and Monolog
Apr 24, 2017 @ 09:46:47

On the Amazon Web Services blog there's a new post showing you how to use the Monolog logging library and a custom AWS extension to ship your logs to Amazon CloudWatch quickly and easily.

Logging and information debugging can be approached from a multitude of different angles. Whether you use an application framework or coding from scratch it’s always comforting to have familiar components and tools across different projects. In our examples today, I am going to enable Amazon CloudWatch Logs logging with a PHP application. To accomplish this, I wanted to use an existing solution that is both already popular and well used, and that is standards compliant. For these reasons, we are going to use the open source log library, PHP Monolog (https://github.com/Seldaek/monolog).

They start by introducing the Monolog library for those not familiar with it and how it relates to the PSR-3 standard. The ultimate goal with their implementation is to allow for the logs to be shipped to CloudWatch and implement some alerting around them. The tutorial then kicks in and they show you how to use Composer to install Monolog and an add-on to interface with CloudWatch. Code is provided to set up the initial logger and how to have it to log messages to different places. They then move over to CloudWatch and define a filter for the JSON data to find successful logins to your application. They also show how to use this same functionality in a Laravel application, contained in a test route.

tagged: aws amazon logging cloudwatch monolog tutorial install usage filter

Link: https://aws.amazon.com/blogs/developer/php-application-logging-with-amazon-cloudwatch-logs-and-monolog/

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/

Rob Allen:
Stand-alone usage of Zend-InputFilter
Feb 15, 2017 @ 09:58:51

Rob Allen has written up a brief tutorial showing you how to use the Zend/Filter component independently from a Zend Framework application. In his example he integrates it into a simple API endpoint.

Any data that you receive needs to be checked and validated. There are number of ways to do this including PHP's filter_var, but I prefer Zend-InputFilter. This is how to use it as a stand-alone component.

He shows you how to get the component installed (along with the Zend ServiceManager) and the creation of a basic validation/filtering on "author" data. He explains the different parts that make up the instance: required, filters and validators. He then shows how to use it in your request and the resulting output if something fails.

tagged: zendframework zendfilter component standalone usage tutorial

Link: https://akrabat.com/standalone-usage-of-zend-inputfilter/

Leonid Mamchenkov:
composer-patches – Simple patches plugin for Composer
Jan 31, 2017 @ 09:22:18

Leonid Mamchenkov has an interesting post to his site detailing a plugin for the popular Composer package management tool that makes it easier to apply patches to the current version of libraries in use: composer-patches

composer-patches is a plugin for Composer which helps with applying patches to the installed dependencies. It supports patches from URLs, local files, and from other dependencies.

This plugin makes it so that, during the normal Composer installation flow, you can apply your own patches to fix functionality that may not be corrected upstream yet. It replaces the need to "fork and fix" in your own version of the repository and cleans up the process to a more automated flow. It can also help when working with multiple people on the same code that's not your own and apply their patches to evaluate their changes.

You can find more information about the composer-packages plugin in the README on its GitHub repository.

tagged: composer patch plugin introduction example usage

Link: http://mamchenkov.net/wordpress/2017/01/31/composer-patches-simple-patches-plugin-for-composer/