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

Hubert Brylkowski:
PHP can’t jump? Thing about recursion.
Dec 26, 2016 @ 15:14:37

Hubert Brylkowski has written up a post to his site looking at recursion in PHP and some of the limitations that can some with traditional methods.

Let’s get straight into the problem – assume we want to calculate nth Fibonacci number. Definition : F(n) = F(n-1) + F(n-2) with seed values F(1) = F(2) = 1 so the most intuitive way to do this is just from the definition (recursive). [...] Yay, everything works, so let’s play with bigger numbers. I would like to know the 35th Fibonacci number. On my machine it takes about 8 seconds. That sucks and takes definitely too long.

He talks about what some of the issues with this normal recursive method is (including how many times the function is called) and a possible way to resolve it. He updates this to use the BCMath handling as the numbers are starting to get larger but soon hits the max nesting level for PHP itself. Instead of traditional recursion, he suggests using a few functions/methods to to "jump" from one call to the next without one having to call the other. He includes some refactoring of this solution and a bit of benchmarking to show the performance gain over traditional methods.

tagged: recursion jump alternative benchmark tutorial fibonacci number

Link: http://brylkowski.com/php-cant-jump-thing-about-recursion/

Toon Verwerft:
Optimizing PHP performance by using fully-qualified function calls
Dec 22, 2016 @ 12:27:55

Toon Verwerft has a post on his site with details about a micro-optimization you can use in your PHP application by using fully-qualified function calls, specifying the namespace even for root level PHP functions.

Today, a little conversation on Twitter escalated rather quickly. Apparently PHP runs function calls differently depending on namespaced or non namespaced context. When calling functions in a namespaced context, additional actions are triggered in PHP which result in slower execution. In this article, I'll explain what happens and how you can speed up your application.

The conversation started with [this tweet]. To understand the difference between global and namespaced function calls better, I'll explain what is going on under the hood.

He starts with this "under the hood" functionality, showing an example of a user-defined, root level function and the opcodes that result. He compares this to the opcodes generated when a namespaced function is called and the extra checking that goes into it (including checking both the namespace and the root levels). Another tweet implied that, because of this difference in checking, fully-qualified function calls would result in a performance increase. He set out to prove it as fact and used the phpbench tool to run four tests with various namespaced and non-namespaced examples. He includes the code he used for the testing and the results from a sample execution. There is, in fact, a slight performance gain from the fully-qualified version. He finishes up the post with some suggestions on using this knowledge including the root-level namespacing for built-in PHP functions.

tagged: performance optimize fullyqualified function call benchmark

Link: http://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/

Symfony Finland:
PHP 7.1 vs. 7.0 performance benchmarks with Symfony
Dec 12, 2016 @ 10:04:09

On the Symfony Finland site they've post together a post sharing some benchmark results of Symfony on PHP 7.0 versus 7.1, the most recent major release of the PHP language with some improvements of its own.

PHP 7.1 was launched on December 1st 2016. This was the first minor release after the release of 7.0 a year ago. PHP 7.0 was a revolutionary product, especially when it comes to memory usage and performance. PHP 7.1 is a more modest upgrade that brings new features and improved performance. But how much has performance improved from a year back?

The benchmarking uses the eZ Platform demo running a full CMS similar to the previous benchmarking done in 2015. The checks were run using:

  • a "clean" environment (no caching, PHP-FPM just restarted and no APC cache)
  • standard requests running in development mode
  • more requests but this time in production mode

The post shares the results with a few graphs showing them in terms of response time for both sequential and concurrent page requests.

tagged: php70 php71 benchmark symfony ezplatform cms results

Link: https://www.symfony.fi/entry/php-7-1-vs-7-0-benchmarks-symfony

SitePoint PHP Blog:
Benchmarking: Can AppServer Beat Symfony’s Performance?
May 19, 2016 @ 10:45:51

The SitePoint PHP blog has posted a new article comparing AppServer and Symfony on a performance level and wonders if the AppServer platform can outperform the framework on some base level functionality.

After the release of the first part of our Appserver series, it was clear through the ensuing discussions on both SitePoint and Reddit that we had touched a nerve for a good number of PHP channel’s devoted readers. I also quickly realized this new (for PHP) technology had a good number of serious doubters. One of the most poignant responses in the discussions was something along the lines of,

Needless to say, those doubtful and critical comments sounded like a real challenge. I was also very interested in finding out where appserver would land, if it were to be benchmarked against another well known PHP framework. [...] I decided to use my favorite framework, Symfony, to make the comparison. This is because appserver, as a stock PHP application server, also offers a good bit of important application functionality similar to Symfony.

They start with the approach they took to the comparison and how they set up the systems to evaluate the difference between the two (including hardware specs). The remainder of the post shares the results of several Apache Bench runs - the raw command line output - and more graphical versions of the same information (bar graphs). While there are a few "wins" on the AppServer side, overall it came in a bit slower (mostly because of the technologies involved in every request, however).

tagged: appserver appserverio performance symfony comparison benchmark results

Link: https://www.sitepoint.com/benchmarking-can-appserver-beat-symfonys-performance/

Mark Baker:
Anonymous Class Factory – The Results are in
May 13, 2016 @ 12:15:17

Following up on his previous post about anonymous classes and a factory to generate them, Mark Baker has posted about the results of some additional research he's done on the topic and four options he's come up with.

A week or so ago, I published an article entitled “In Search of an Anonymous Class Factory” about my efforts at writing a “factory” for PHP7’s new Anonymous Classes (extending a named concrete base class, and assigning Traits to it dynamically); and about how I subsequently discovered the expensive memory demands of my original factory code, and then rewrote it using a different and (hopefully) more memory-efficient approach.

Since then, I’ve run some tests for memory usage and timings to assess just how inefficient my first attempt at the factory code was, and whether the new version of the factory really was better than the original.

His four options that finally worked somewhat as he'd wanted were:

  • A factory that returns an instance of a concrete class using the traits he wants
  • A factory that returns an anonymous class extending a concrete class that uses the traits
  • His original Anonymous Class factory and extending the result with the traits
  • His second version of the Anonymous Class factory that creates the instance, caches it and returns a clone

He also includes the code he used to run the tests of each factory method and shares some of the resulting benchmarks (with a few surprises).

tagged: anonymous class factory results options benchmark

Link: https://markbakeruk.net/2016/05/12/anonymous-class-factory-the-results-are-in/

Marc Schmidt:
PHP High-Performance - Follow Up with Symfony/Jarves.io and PHP-PM
May 02, 2016 @ 12:08:37

In a follow up to his previous article about high performance PHP with React's help, Marc Schmidt has returned with a follow up post two years after the fact with some updates and additional information.

This is a follow up article on “Bring High Performance Into Your PHP App”, which went quiet viral with over 100k visits. This does not only show that many people still struggle with PHP and its performance, but also that people are highly interested in a solution to this kind of issues. PHP-PM could be one solution. But first things first. Over two years later since my blog post about high-performance things have changed dramatically.

[...] When I hacked together some lines of code back then in 2013 I never though that this kind of application style would ever succeed in the PHP world. [...] However, things have changed there as well.

He talks about some of the advancements that have been made since his previous post including PHP 7, improvements in PHP-FM and the HttpKernel component of the Symfony framework. Along the lines of bringing even more performance to PHP applications with React, they created an adapter to link the two. The post covers some of the currently open issues, the "good things" about it and some of the design issues to keep in mind when using it. He ends the post talking about where the PHP-PM project is now and some of the benchmarks about performance between PHP-PM and PHP-FPM.

tagged: performance react httpkernel phppm phpfpm adapter benchmark

Link: http://marcjschmidt.de/blog/2016/04/16/php-high-performance-reactphp-jarves-symfony-follow-up.html

Jeff Geerling:
Yes, Drupal 8 is slower than Drupal 7 - here's why
Mar 25, 2016 @ 12:05:44

Jeff Geerling has an interesting post to his site showing the results of some of his own testing around the performance of Drupal 8 versus Drupal 7...and that 8 comes out to be slower than 7. He also includes some of the things that the Drupal project is doing to help the situation.

When some people see reports of Drupal 8 being 'dramatically' slower than Drupal 7, they wonder why, and they also use this performance change as ammunition against some of the major architectural changes that were made during Drupal 8's development cycle.

First, I wanted to give some more concrete data behind why Drupal 8 is slower (specifically, what kinds of things does Drupal 8 do that make it take longer per request than Drupal 7 on an otherwise-identical system), and also why this might or might not make any difference in your choice to upgrade to Drupal 8 sooner rather than later.

He shares the results of some of his own benchmarking on a cluster (bramble) of Raspberry Pis for the requests per second on the standard setup for each version. He includes the output from an XHProf profiling run too, showing the large call stack on both sides, not just Drupal 8. He then talks about some of the Drupal 8 updates that are included to help mitigate some of these issues: architecture changes, easier caching, authenticated user handing and slow loading content management.

tagged: drupal8 drupal7 performance raspberrypi cluster testing results benchmark

Link: http://www.jeffgeerling.com/blog/2016/yes-drupal-8-slower-drupal-7-heres-why

Johannes Schlüter:
References - Still bad in PHP 7
Feb 19, 2016 @ 09:18:45

Johannes Schlüter has a post to his site that talks about references in PHP 7 and how they're "still bad" based on some of his previous findings.

I'm known for telling "Don't use references" (also as video) as those cause different problems (i.e. with foreach) and hurt performance. The reason for the performance loss is that references disable copy-on-write while most places in PHP assume copy-on-write. Meanwhile we have PHP 7. In PHP 7 the internal variable handling changed a lot among other things the reference counting moved from the zval, the container representing a variable, to the actual element. So I decided to run a little test to verify my performance assumption was still valid.

He includes his testing code that calls a function (strlen) in a loop and compares the handling against two methods, one passing by reference the other not. The results are shown in time taken to execute. He compares the results for PHP 5 and PHP 7, noting that PHP 7 is marginally better when passed by value, by-reference is still about the same.

tagged: reference php7 php5 compare value byreference byvalue test benchmark execution

Link: http://schlueters.de/blog/archives/180-References-Still-bad-in-PHP-7.html

Djordje Kovacevic:
PHP cloud hosting comparison (OpenShift vs Heroku vs Fortrabbit)
Jan 22, 2016 @ 11:54:01

In this post to his site Djordje Kovacevic shares the results of his evaluation of hosting providers in the platform-as-a-service arena for hosting PHP applications: OpenShift, Heroku and Fortrabbit.

I want PHP 5.6+, so I did some basic testing of those services to pick cheep and good solution to host my blog. OpenShift because I use it and it's free for 3 small gears, it was pretty good solution few years ago. Heroku because I used it for Ruby on Rails projects and they support multiple languages (even multiple build packs for one project)! I used FortRabbit too, so I decided to test theirs new apps.

For his testing he used a simple Laravel (v5.2) application with a handful of routes - something simple just to test out the setup and deployment processes. There is a "tl;dr" of the results but he also gets a bit more in-depth on what each service has to offer and some of the pros and cons of each. He also includes the results of some basic performance testing on the instances, linking to the raw output if you'd like to run your own metrics against it.

tagged: heroku openshift fortrabbit paas platformasaservice hosting provider comparison pro con benchmark

Link: http://djordjekovacevic.com/articles/php-cloud-hosting-comparison-(openshift-vs-heroku-vs-fortrabbit)

Symfony Finland:
Symfony Benchmarks: Symfony Proxy vs. Varnish
Jan 05, 2016 @ 13:29:51

The Symfony Finland blog site has worked up some benchmarks comparing the Symfony Proxy versus Varnish and shared the results in this new post. The Symfony Proxy is a tool built in to the framework to help with caching responses automatically. Varnish, however, is a separate tool optimized to handle the caching of the same content but outside of the application completely.

In the previous articles we have evaluated PHP performance on different runtimes (PHP 5.6, HHVM, PHP 7) as well as how it behaves when adding server resources (CPU & RAM) using eZ Platform - a CMS built on the Symfony Framework.

In production environments Symfony and eZ Platform are likely ran behind the Varnish Reverse Proxy, which we'll evaluate next by comparing it to the built in Symfony Proxy.

They once again use the eZ platform demo application as the software under test on an 8 Core machine. The results aren't overly surprising if you're familiar with Varnish at all. Software-based caching layers are helpful but when you are able to remove the processing overhead of it from an application, you're better off.

tagged: symfony benchmark symfonyproxy varnish ezplatform statistics

Link: https://www.symfony.fi/entry/symfony-benchmarks-symfony-proxy-vs-varnish