Comparative Load Testing: Laravel on PHP Apache vs PHP Nginx

Paldavidi
3 min readSep 17, 2024

--

In the world of application development, server performance plays a crucial role in user satisfaction. One way to assess server performance is through load testing. In this article, we will discuss the results of load testing conducted on two different servers running the Laravel application: one on php:8.1-apache and the other on php:8.1-fpm nginx. The goal is to compare the performance of both servers under load.

A. Tools and Testing Method:

The testing was carried out using JMeter with the following configuration:

- Number of Threads (users): 300

- Ramp-up Period: 1 second

- Loop Count: 1

jmeter setting

With this setup, JMeter simulates 300 users accessing the application within 1 second, and each user makes a single request to the server.

B. Testing Result

  1. PHP Apache
  • Execution time: 21s
Execution time for php apache
  • Peak CPU Usage = 1084.89%
Peak CPU php apache
  • Summary
Test Result php apache

- Samples: 300

- Average Response Time: 16184 ms

- Minimum Response Time: 8968 ms

- Maximum Response Time: 18572 ms

- Standard Deviation: 2329.02 ms

- Error Rate: 0%

- Throughput: 16.0 requests/second

- Received Data: 672.46 KB/second

- Sent Data: 3.73 KB/second

- Average Data Size: 42915.7 bytes

2. PHP-FPM NGINX

  • Execution time: 16s
Execution time for php-fpm nginx
  • Peak CPU Usage = 488.35%
Peak CPU php-fpm nginx
  • Summary
Test Result php-fpm nginx

- Samples: 300

- Average Response Time: 8901 ms

- Minimum Response Time: 4666 ms

- Maximum Response Time: 12548 ms

- Standard Deviation: 2250.84 ms

- Error Rate: 0%

- Throughput: 23.5 requests/second

- Received Data: 990.77 KB/second

- Sent Data: 5.92 KB/second

- Average Data Size: 43182.5 bytes

C. Comparative Analysis:

The results show that the server running on php:8.1-fpm nginx, consistently delivers better performance than uses php:8.1-apache. Key takeaways from the testing include:

Execution Time: The Nginx server completed the test in 16 seconds, 5 seconds faster than Apache, which took 21 seconds.

CPU Usage: Peak CPU usage on the Nginx server was only 488.35%, while on Apache, it reached 1084.89%. This indicates that Nginx is more efficient in managing CPU resources.

Throughput: Nginx handled more requests per second (23.5/s) compared to Apache (16.0/s), showing that Nginx can serve more users simultaneously without a drop in performance.

Conclusion:

This load testing highlights the advantages of php-fpm Nginx in terms of CPU efficiency and processing speed compared to php-apache. For developers looking for optimal performance, especially in applications with high user traffic, the Nginx configuration provides superior results.

Therefore, if you’re considering a server setup for your Laravel application, opting for php-fpm Nginx can be a smart choice to enhance application speed and resource efficiency.

--

--