X
    Categories: Learn Laravel Tutorials, Tips And Guides

PHP 5.6 Vs PHP 7 – Performance Benchmarks With Laravel 5

Laravel is rapidly becoming a popular choice for PHP projects. The framework has established its reputation after the release of version 5.x. In the same vein, PHP recently received a major update in the form of PHP 7.1.x.

It is an established fact that Laravel has a solid codebase and provides optimized performance for all lightweight and enterprise level applications. However no statistics about Laravel 5 benchmarks and its performance with PHP 5.6 and PHP 7 are widely available.

Recently Taylor Otwell, in an interview with Cloudways, mentioned the versatility of  Laravel application development i the following words:

Laravel is a very modern framework. Job queueing is included out of the box. Integration with web-socket / real-time tools like Socket.io and Pusher is included out of the box. In addition, there is very strong support for autowired dependency injection and convenient unit testing. So, I think if you are building a modern, robust web application, Laravel is the strongest contender in the PHP ecosystem simply because it includes the features needed to build modern, maintainable, real-time, distributed web applications. In addition, it has an extensive video library of over 900 tutorials at Laracasts.

I decided to test this claim by testing Laravel’s performance for both php 5.6 and 7.0 on Cloudways. Here is how it all went:

Test Scenario

I used the Blitz tool for this test.

The test scenario is divided into two cases:

The first case is:

  • Laravel 5.4 demo application
  • Cloudways Managed DigitalOcean server : 8GB
  • PHP 5.6
  • No caching libraries
  • Test Duration: 5 min
  • No of Users: 250

Now in the second case, I upgraded the server to PHP 7.0. The rest of the parameters remained the same:

  • Laravel 5.4 demo application
  • Cloudways Managed DigitalOcean server : 8GB
  • PHP 7.0
  • Test Duration: 5 min
  • No of Users: 250

To start the test, I signed up to Cloudways and  launched a PHP stack with Laravel application from a London data centre. I left all the settings to default. To ensure more clarity of the statistics, I did not turn on any caching options such as Varnish or Redis on the server.

Laravel Benchmarking for PHP 5.6

This test was conducted using blitz.io. The test ran continuously for 5 minutes . You can find the demo Laravel application Github repo here.

Here are the results of the test:

Response Time

The graph is pretty much self explanatory. Below 50 users, the server responded fast enough i.e. 500ms. As the number of users increased, the response time also increased. The maximum response time I got here is 1631 ms, when 246 users were present on the server

Hit Rate

The server saw around 25 hits/second for 50 users. However, as the users increased to 250, the hit rate rose to 100+ per second. I saw a little timeout at 2.5th minute of the test for one or two users. However, the server stabilized itself and continued to handle the hits. I did not see any more errors (including time out) during the process.

In the span of 300 seconds, the server handled 22,375 hits without any visible signs of server overload and all request were successful.

The Complete Analysis

During the test, the blitz tool generated 22,375 hits successfully in 300 sec. In addition, the Laravel app received 427.91 MB of data. The average hit rate of 75/second translated to about 6,444,000 hits per day. Here is the summarized picture of the test:

Laravel Benchmarking for PHP 7.0

In the second half of the test, I upgraded my managed Digitalocean server to PHP 7.0. Cloudways has the PHP package update option in Server Management tab, where you can select PHP 5.6 or 7.0 from the options.

Once the server was updated, I ran the blitz test again on the server with the same Laravel application.

Let’s see what results I got:

Response Time

This time, I saw significant improvement in the response time of the server. Below 200 users, the server responded within 300ms. When the number of users increased to around 240+, the average response time was around 3.5 seconds. At this point, I saw significant differences between the two PHP versions with Laravel.

Hit Rate

I also saw improvement in the hit rate as well. When compared to PHP 5.6, the numbers increased significantly with 50+ additional hits. Even with this load, the server did not see errors and timeouts.

In the span of 300 seconds, the server handled 29,214 hits without any issues. Also the max hit rate was also increased with 56 more hits/sec.

The Complete Analysis

During the test, the blitz tool generated 29,214 hits successfully in 300 seconds. The Laravel app received 420.31 MB of data. The average hit rate of 97/sec translates to about 8,413,632 per day. Here is the summarized picture of the test:

The Winner

The test generated the following statistics

Parameters Laravel 5.4 + PHP 5.6 Laravel 5.4 + PHP 7.0
Region Ireland Ireland
Fastest Response Time 268 ms 257 ms
Slowest Response Time 1,631 ms 386 ms
Average Response Time 553 ms 274 ms
Duration 300 seconds 300 seconds
Load 1-250 Users 1-250 Users
Total Hits 22,375 29,214
Average Hits 75/second 97/second
Transferred 3.65 MB 4.69 MB
Received 424.34 MB 420.31 MB

The results clearly indicate that PHP 7.0 outperforms PHP 5.6 using Laravel on all major comparison points. This means that the upcoming widespread adoption of PHP 7.x will result in increased performance across the board. The result would be faster and higher performing PHP applications powered by all major frameworks. I think the Laravel 5 benchmarks and its performance with PHP 5.6 and PHP 7 would becoming the North Star for future PHP projects. 

Shahroze Nawaz: Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He’s always in search of new frameworks and methods to implement them. Besides his coding life, he loves movies and playing soccer with friends. You can email him at shahroze.nawaz@cloudways.com