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

PHP 5.6 vs. PHP 7: Laravel Performance

DZone's Guide to

PHP 5.6 vs. PHP 7: Laravel Performance

Check out some performance benchmarks of PHP 5.6 and PHP 7 with Laravel 5 to see why adopting PHP 7.x will result in increased performance across the board.

· Performance Zone
Free Resource

Transform incident management with machine learning and analytics to help you maintain optimal performance and availability while keeping pace with the growing demands of digital business with this eBook, brought to you in partnership with BMC.

Laravel is a modern PHP framework that is ideal for all the lightweight and enterprise level applications because of a host of mature features and packages. With the release of PHP 7, Laravel has rapidly become the most popular choice of the community because of its very favorable benchmarks with PHP 7.

PHP 5.6 and PHP 7 Benchmarks With Laravel 5

It is an established fact that Laravel has a solid codebase that greatly streamlines the development process. To gauge the performance of Laravel with PHP 7, I performed a load test on Laravel using both PHP 5.6 and PHP 7. The comparison shows that the performance of Laravel with PHP 7 is significantly better than other combinations.

Recently, Taylor Otwell, in an interview with Cloudways, mentioned the versatility of Laravel application development in 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.

  • Number 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.

  • Number of Users: 250.

To start the test, I signed up to Cloudways and launched a Laravel application on a PHP Stack from a London data center. To ensure more clarity of the statistics, I kept everything to default settings. In order to actually test the performance of the Laravel application, I did not activate 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 mostly self-explanatory. The server responded in 500ms when the number of users was below 50. The response time increased as the number of users increased. The maximum response time I got was 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 the timeout error) 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.

Here are the results I saw.

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 increased by 56 additional 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 results:

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 will become the North Star for future PHP projects.

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Topics:
laravel 5 ,php ,benchmarks ,performance

Published at DZone with permission of Saquib Rizwan. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}