X
    Categories: Learn Laravel Tutorials, Tips And Guides
Reading Time: 4 minutes

Laravel performance testing is an important aspect of the growth of the framework. Developers in particular need to checkout benchmarking numbers because of the direct impact on application performance. In many cases, choosing the Laravel PHP 7 combination could prove to the most basic decision that developers could make for their projects. 

Laravel performance benchmarks for PHP 7.0, 7.1 and 7.2 is a hot topic in the industry because of the popularity of Laravel for web projects. So I decided to test it for for all three popular versions of PHP 7.x For the purpose of this article, I decided to use a Laravel single page app with Vue.js. To replicate the numbers, you could use any other Laravel app. (however, note that your results could vary) .

This test was conducted using Apache Benchmark.

Prerequisites

For the purpose of this tutorial, I assume that you have a Laravel application installed on a web server. My setup is:

First Case

  • Cloudways Managed Linode server : 2GB
  • Datacenter: Bangalore
  • PHP 7.0
  • No caching libraries
  • No of Users: 50, Requests 500-1000
  • Laravel 5.5 with PHP 7.0

Second Case

  • Cloudways Managed Linode server : 2GB
  • Datacenter: Bangalore
  • PHP 7.1
  • No caching libraries
  • No of Users: 50, Requests 500-1000
  • Laravel 5.5 with PHP 7.1

Third Case

  • Cloudways Managed DO server : 1GB
  • Datacenter: Bangalore
  • PHP 7.2
  • No caching libraries
  • Number of Users: 50, Requests 500-1000
  • Laravel 5.5 with PHP 7.2

Now, to simplify the process, I decided that I don’t want to deal with server management issues. In addition, I needed a dependable stack that supports both versions of PHP and Laravel. Since Cloudways Laravel hosting offers this combination, I hosted the test app on the platform. If you wish to replicate the test, I strongly recommend signing up for a free Cloudways account and then follow the GIF for server and app setup:

Here is a list of active services on the server:

 

You might also like: Enhanced Cloudways Staging Environment Is Now Available for All Users

Laravel 5.5 & PHP 7.0 Benchmark: 500 Requests & 50 Concurrent Users

Fire up the SSH terminal and go to public_html folder. Type the following command:

ab -k -n 500 -c 50 http://phplaravel-144478-440242.cloudwaysapps.com/

You might also like: Tips for Laravel Performance Optimization

Upgrade the PHP Version

Cloudways sets 7.0 as the default PHP version. However, you could easily change the PHP version by going to Settings & Packages tab and then change the version from the relevant dropdown.

 

Laravel 5.5 & PHP 7.1 Benchmark: 500 Requests & 50 Concurrent Users

For the next part, enter the following command in the SSH terminal:

ab -k -n 500 -c 50 http://phplaravel-144478-440242.cloudwaysapps.com/

Laravel 5.5 & PHP 7.2 Benchmark: 500 Requests & 50 Concurrent Users

Fire up the SSH terminal and go to public_html folder. Type the following command:

ab -k -n 500 -c 50 http://phplaravel-144478-440242.cloudwaysapps.com/

Install Laravel 5.6

PHP 7.2 is the basic requirement for installing Laravel 5.6. Since the default PHP version is 7.0, it is important to update the version. Fortunately, Cloudways makes this change incredibly easy. Just go to Settings & Packages tab and change the version from the relevant dropdown. Once you have decided the Laravel PHP 7 combination, the next step is the installation of Laravel 5.6. Start by issuing the Composer create-project command in your terminal:

composer create-project --prefer-dist laravel/laravel blog

Add to .htaccess File

If the .htaccess file that ships with Laravel does not work, try this alternative:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

When the Laravel 5.6 is properly installed, you will see the following welcome page:

Laravel 5.6 & PHP 7.2 Benchmark: 500 Requests & 50 Concurrent Users

For the next part, enter the following command in the SSH terminal:

ab -k -n 500 -c 50 http://phpstack-166178-480360.cloudwaysapps.com/blog/public/

In a Nutshell

The Laravel PHP 7.x performance test generated the following statistics

Sno Parameters Laravel 5.5 + PHP 7.0 Laravel 5.5 + PHP 7.1 Laravel 5.5 + PHP 7.2 Laravel 5.6 + PHP 7.2
1 Region Bangalore Bangalore Bangalore Bangalore
2 Concurrency Level 50 50 50 50
3 Time Take For Test 9.928 seconds 10.007 seconds 6.843 seconds 6.843 seconds
4 Complete Requests 500 500 500 500
6 Total Transferred [bytes] 1881630 1881751 1709476 1881998
7 Keep ALive Requests 483 489 488 488
8 Request Per Second 50.36 49.96 73.06 73.06
9 Time Per Request 992.874 ms 1000.707 ms 684.348 ms 684.348 ms
10 Time/Request [mean ms](mean across concurrent users) 19.857 20.014 13.687 13.687

Wrapping it Up

From this Laravel benchmark results, it is clear that it performed very similar on PHP 7.0 and 7.1. This Laravel and PHP 7 benchmark results show that the developers do not have to worry about the performance of the Laravel PHP 7 combination (whether it is PHP 7.0 or 7.2) .However , Laravel 5.6 has handled slightly more request with 7.2 as compared to PHP 7.0 & PHP 7.1 .

Please Retweet if you liked this article, and don’t hesitate to follow me on Twitter. Thanks for reading.

 

Pardeep Kumar :Pardeep is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He love to work on Open source platform , Frameworks and working on new ideas. You can email him at pardeep.kumar@cloudways.com