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

Lakion Blog:
How we sped up Sylius' Behat suite with Blackfire
Dec 01, 2015 @ 12:08:57

On the Lakion blog there's a recent post sharing how they used the Blackfire.io profiling service to [speed up their application's tests] (Behat)(http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire) and find the "pain points" to fix.

Feedback time is one of the most crucial factors during development and the red - green - refactor cycle. In case of Sylius, the full build used to take two and a half hour, including 55 minutes for only PHP 5.6 jobs. Waiting so long for feedback is not an option for a project of this size and with so many active contributors. As much as I am Xdebug fan, I have never really used it for profiling - the snapshots generation was slowing down the profiled script significantly and resulted in monstrous files, which weren't easy to read.

Half a year after I have first heard of blackfire.io I decided to give it a try. It resulted in a series of pull requests that speeds up Sylius test suites 6 times and reduces memory usage to one tenth.

They go through some of the major bottlenecks that the service helped them locate including:

  • an issue with the login process and their role evaluation handling
  • problems with time spent doing router initialization
  • Doctrine performance issues running it without a class metadata cache

For each item they describe what the service was reporting and how they corrected it in the application. Most of the changes were relatively small, fortunately. They also link to the results from before and after the changes so you can see the difference. As their environment is Symfony-based they end the post with some other helpful Symfony tips to getting the most out of your application and enhancing its performance in a few simple ways.

tagged: blackfireio behat test suite performance improvement profiling

Link: http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire

Zend Developer Zone:
Developing a Z-Ray Plugin 101
Nov 04, 2015 @ 10:44:13

The Zend Developer Zone has posted a tutorial showing you the basics of creating a plugin for Z-Ray, the tool from Zend that provides details and metrics around the execution of your application.

One of the great things about Z-Ray is the ability to extend it to display any info you want about your app. This is done by creating plugins. In this tutorial I’m going to describe how to create a new Z-Ray plugin. I’ll be supplying code snippets to insert in the various plugin files but of course feel free to replace it with your own code when possible.

They start by describing how Z-Ray shows its data and offering two options - the default panel or a custom panel. They choose the custom panel and show you how to:

  • create the template for the panel
  • make the module directory and zray.php
  • and Modules.php file to define the plugin

There's also a section on how the Z-Ray plugin traces through the execution of your application, illustrating with a DummyClass. They include the code to set up the Trace and define which methods and actions to watch. Finally they relay this information back out to the custom panel view via Javascript collection and the code to show the results.

tagged: zray plugin custom performance dummyclass execution tracer tutorial

Link: http://devzone.zend.com/6826/developing-a-z-ray-plugin-101/

Julien Pauli:
Huge Page usage in PHP 7
Oct 30, 2015 @ 12:16:48

In this post to his site Julien Pauli looks at the concept of "huge pages" and how it relates to some of the behind the scenes work done in PHP 7 to improve memory usage.

Memory paging is a way Operating Systems manage userland process memory. Each process memory access is virtual, and the OS together with the hardware MMU must translate that address into a physical address used to access the data in main memory (RAM).

Paging memory is dividing memory in chunks of fixed size, called pages. [...] Why use huge pages? The concept is easy. If we make the OS Kernel use bigger page sizes, that means that more data can be accessed into one single page. That also means that we'll suffer from less TLB miss, once the page translation is stored into the TLB, because one translation will now be valid for more data.

He briefly covers how some updated memory handling and opcode restructuring helps PHP 7 perform even better, especially when it comes to the OPCache handling. He talks about the changes made in the extension specifically to support the "huge pages" idea, complete with code examples (in C) of how this was accomplished.

tagged: huge page php7 memory improvement performance opcache

Link: http://jpauli.github.io/2015/10/28/huge-page.html

SitePoint PHP Blog:
Memory Performance Boosts with Generators and Nikic/Iter
Oct 20, 2015 @ 09:31:24

On the SitePoint PHP blog there's a tutorial posted showing you how to get some performance gains in your PHP applications using the "Iter" library from Nikita Popov.

First came arrays. Then we gained the ability to define our own array-like things (called iterators). But since PHP 5.5, we can rapidly create iterator-like structures called generators. These appear as functions, but we can use them as iterators. They give us a simple syntax for what are essentially interruptible, repeatable functions. They’re wonderful!

And we’re going to look at a few areas in which we can use them. We’re also going to discover a few problems to be aware of when using them. Finally, we’ll study a brilliant library, created by the talented Nikita Popov.

They start with a common problem: loading information line-by-line from a CSV file. They do some filtering and merging of the values but point our a major flaw - large files. These would drag down performance quite a bit and generators might just make for a good solution. He shows a simple "read CSV" generator to get the lines in the file while also reducing the memory needed. Unfortunately the array_map/array_filter methods he was using for sorting don't work with generators. The nikic/iter helps fix this. Code examples are included showing it in use performing the same operations as before. He ends the post with a few other "fun things" including array flattening, slicing and rewinding generators.

tagged: memory performance boost generator nikic iter library tutorial

Link: http://www.sitepoint.com/memory-performance-boosts-with-generators-and-nikiciter/

Creating flamegraphs with XHProf
Jul 30, 2015 @ 10:08:27

The Platform.sh blog has a post showing you how to create flamegraphs with XHProf for your application's execution and overall performance. A "flamegraph" is just a different sort of graph stacking up the execution times for the methods and functions in your application so they look more like a "flame" than just numbers.

One of the most frequent needs a web application has is a way to diagnose and evaluate performance problems. Because Platform.sh already generates a matching new environment for each Git branch, diagnosing performance problems for new and existing code has become easier than ever to do without impacting the behavior of a production site. This post will demonstrate how to use a Platform.sh environment along with the XHProf PHP extension to do performance profiling of a Drupal application and create flamegraph images that allow for easy evaluation of performance hotspots.

While they show it at work on a Platform.sh instance, the method can be altered slightly to work with your own application with the right software installed. Their example uses the brendangregg/FlameGraph library to do the majority of the graphing work. He shows how to have the code switch on XHProf during the execution and where to put the file for later evaluation. They include the resulting directories and files created from the execution and how to view the resulting (SVG-based) graphs directly in a browser.

tagged: xhprof flameframe execution performance graph tutorial platformsh

Link: https://platform.sh/2015/07/29/flamegraphs/

SitePoint PHP Blog:
Speeding up Existing Apps with a Redis Cache
Jul 28, 2015 @ 10:27:06

The SitePoint PHP blog has posted a tutorial that want to help you speed up your applications with Redis, adding in caching to help reduce the overall processing load your app has to expend.

The application in question, when executing a query, runs off to Diffbot’s API and makes it query the dataset. The subset is then returned and displayed. This can take up to 5 or so seconds, depending on the busyness of Diffbot’s servers. While the situation will undoubtedly improve as they expand their computational capacity, it would be nice if a query executed once were remembered and reused for 24 hours, seeing as the collection is only refreshed that often anyway.

Considering the fact that implementing this cache costs us literally nothing (and actually reduces costs by reducing strain on the servers), adding it in is an easy win, even if it weren’t used as often as one would hope. There is no reason not to add it – it can only benefit us.

He helps you get Redis up and running as a service on the local system and installing the Predis, the PHP library you'll use to talk with Redis for setting and getting the cached information. He includes a few code snippets showing how to send the search off to the DiffBot API, return the results and push them into the cache as serialized data with a day long timeout. He also mentions the phpiredis extension to reduce some of the overhead that could be cause by using a PHP library versus an extension.

tagged: speed performance redis cache tutorial introduction predis phpiredis

Link: http://www.sitepoint.com/speeding-up-existing-apps-with-a-redis-cache/

BitExpert Blog:
Think About It: PHP/PostgreSQL Bulk Performance (Part 3)
Jul 24, 2015 @ 10:46:06

On the bitExpert blog they've continued their "Think About It" series of posts looking at optimizations that can be made to different technologies in their stack to increase performance. In this third part of the series they focus in on the changes made to help speed things up with the PostgreSQL database backend.

This article is the last of a three-part series and describes how we optimized the persistence process of bulk data in our code in combination with PostgreSQL. Make sure you covered the first article about how we tweaked PHPExcel to run faster while reading Excel and CSV files and the second article about how we optimized our data processing and reached performance improvements tweaking our code.

They work from the example code provided at the end of part two and update the "update" handling to optimize it a bit. By default it executes an update query for each record so, instead, they modified it to perform a bulk update with an "update from values" format. They could then migrate to a "save all" handler with the complete set of records to save.

tagged: performance postgresql bulk series part3 tutorial phpexcel excel csv

Link: https://blog.bitexpert.de/blog/think-about-it-php-postgresql-bulk-performance-part-3/

Digital Ocean Blog:
Getting Ready for PHP 7
Jul 16, 2015 @ 12:31:48

The Digital Ocean blog has posted a guide to help you get ready for PHP7, the next major release of the PHP language. There's a lot of new functionality and changes coming with the release along with plenty of performance and consistency improvements.

2015 has been an important year for PHP. Eleven years after its 5.0 release, a new major version is finally coming our way! PHP 7 is scheduled for release before the end of the year, bringing many new language features and an impressive performance boost. But how this will impact your current PHP codebase? What really changed? How safe is it to update? This post will answer these questions and give you a taste of what’s to come with PHP 7.

They start with a brief look at some of the overall performance improvements PHP7 will introduce and a few things to watch out for that may break with the upgrade (like deprecated features and engine exceptions). From there they get into some of the new language features:

  • New operators (spaceship, null coalesce)
  • Scalar type hinting
  • Return type hinting

They each have brief code examples showing how they'd be put to use but there's also links to other resources with more information if you need them.

tagged: introduction php7 prepare changes deprecate update performance

Link: https://www.digitalocean.com/company/blog/getting-ready-for-php-7/

BitExpert Blog:
Think About It: Loop Iteration Per
Jul 15, 2015 @ 09:30:16

On the BitExpert.com blog Florian Horn continues his "Think About It" series (part 2) looking at performance enhancements that can be made when using the PHPExcel library and in their overall data processing. In this article they build on part one and share a few more handy performance tweaks.

This article is the second of a three-part series and describes how we optimized our data processing and reached performance improvements tweaking our code. Make sure you covered the first article about how we tweaked PHPExcel to run faster while reading Excel and CSV files.

He shows how they replaced some repeated looping and generating entities with an index-cached set. This set uses the ID of the element as the index and makes it faster and easier to reference the value. This dropped their overall loop handling of the imported data by half.

tagged: phpexcel performance update tweak part2 series indexcached set

Link: https://blog.bitexpert.de/blog/think-about-it-loop-iteration-performance-part-2/

PHP 7 and script languages future: insights from lead Zend.com developer
Jul 13, 2015 @ 11:21:02

The Amasty.com site has posted an article featuring an interview with Dmitry Stogov about his background and the next major release of PHP - PHP 7.

PHP is used on 81.9% of websites all over the world and has celebrated its 20th birthday some time ago. We talked to the PHP 7 lead developer and Zend Technologies Chief Performance Engineer – Dmitry Stogov. He spoke about the newest trends in PHP development and the world of script languages.

He answers questions about:

  • How and why he started coding
  • Why he chose PHP and ended up at Zend
  • The work he's contributed to PHP and more specifically PHP7

This includes the work done on the PHPNG performance improvements for the language that was integrated into the main codebase. He talks about some of the testing and development hurdles they had to overcome and what the most important features are to an end user. They also talk some about the future of PHP, it's overall perception in programming communities and some of the features he finds best in modern PHP development. They end the post asking Dmitry about some of his own interests and any advice he can give to more junior developers.

tagged: dmitrystogoy interview php7 phpng performance background features language

Link: https://blog.amasty.com/php-7-and-script-languages-future-insights-from-lead-zend-com-developer/