Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

PHP 7 in Production

DZone's Guide to

PHP 7 in Production

Since the announcement of the stable release of PHP 7.0.0 on December 3rd, I’ve been excited to see what the performance gains would be in a live production environment. I know that there are a lot of PHP skeptics, but there is a reason that they jumped from PHP 5 to PHP 7.

· Performance Zone
Free Resource

Download our Introduction to API Performance Testing and learn why testing your API is just as important as testing your website, and how to start today.

Since the announcement of the stable release of PHP 7.0.0 on December 3rd, I’ve been excited to see what the performance gains would be in a live production environment. I know that there are a lot of PHP skeptics, but there is a reason that they jumped from PHP 5 to PHP 7. This upgrade represents a big move forward in PHP code efficiency. As I consider myself somewhat of a data scientist, I wanted to write up my experience in such a way that anyone could go out and duplicate the results that I got.

At ZipBooks, we have one server that runs a Laravel-based accounting application and another server that runs a WordPress website. Our PHP upgrade on our Laravel app is yet to be completed but I have finished the upgrade for the server running Wordpress.

Our Setup

We have Wordpress 4.4 running on a single-core Digital Ocean server. There is nothing fancy about it. We use Nginx, PHP, and vanilla MySQL. I used New Relic to generate the graphs and Apache Bench to run some basic stress tests.

Method

I upgrade PHP on the production server to hold as many variables constant as I could. I was most interested in what the change in requests per second would be at 100% CPU load.

Stress Testing PHP 5

I hadn’t yet set up any kind of server monitoring on our Wordpress server so I took this opportunity to set that up so I could make some nice graphs to look at. Then I installed Apache Bench and ran a couple stress tests to see what it would take to push our CPU utilization to 100%.  I ended up sending 10,000 requests with 100 concurrent connections. I want to make sure that I had a big enough sample to get a meaningful throughput metric.

Here is the command I used:


sudo ab -n 10000 -c 100 https://zipbooks.com/


Here are the results:

test before.PNG

You can see that I did a good job of stressing our poor single core server. The main metric I am going to compare is requests/second.

The little bump before was me just testing out Apache Bench to see what a baseline test would do in terms of resource demand.

PHP 7 Upgrade

I wouldn’t consider myself a server management wizard, but even for me the upgrade was extremely straight-forward. I used the instructions in the comments here.

How to add a Personal Package Archive (PPA)

  1. Add ‘add-apt-repository’ if you don’t already have it:

$ apt-get install python-software-properties
  1. Add PHP 7 package from Ondřej Surý’s website.

$ add-apt-repository ppa:ondrej/php-7.0


  1. Backup any config files that you made custom changes to because you about to over write them.

  2. The next command is going to update your package lists, remove PHP 5 and its dependencies and install PHP 7.

$ apt-get update && apt-get purge php5-fpm && apt-get --purge autoremove && apt-get install php7.0-fpm php7.0-mysql


  1. In my case, I had to go into my Nginx configuration file and change where is was looking for the php socket. I had a little issue there because my php5-fpm socket was in a different folder.

  2. Restart PHP and Nginx.

Stress Testing PHP 7

I liked the approach of stress testing the same server before and after the upgrade because it eliminates a lot of potential unmeasurable variables that could affect a benchmark test. So I have the same server, the same programs, and the same benchmark test. The only thing that has changed in the version of PHP that I am testing.

Here are the results:

test after.PNG

Looks like our Wordpress website went from being able to handle 14 requests / second to 46 requests / second. That is a 228% gain in throughput. It cut the CPU load by 50%.

half the CPU.PNG

Below is a map of CPU usage over time during the two tests.

test results new relic.png

Shameless Plug

I am working on a free accounting software program that is great for tracking expenses and your time as a contractor. You can set people up on recurring billing and process payments via cc. It is built on Laravel and once we upgrade to PHP 7 it will run snappier than ever.


ZipBooks is also pretty great at recurring billing. Here's our invoice template.

Find scaling and performance issues before your customers do with our Introduction to High-Capacity Load Testing guide.

Topics:
php7

Published at DZone with permission of Brad Hanks. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}