Copied!
Laravel
Node

Ultimate Guide to ApacheBench (ab) for High-Performance Web Testing

apachebench-laravel-load-test
Shahroz Javed
Dec 22, 2025 . 170 views

Testing the performance of your Laravel applications and web servers is crucial before going live. ApacheBench (ab) is a lightweight, command-line benchmarking tool that allows developers to simulate multiple requests, measure response times, and identify bottlenecks in their applications.

Introduction

ApacheBench is a tool originally developed for the Apache HTTP server, but it works with any HTTP server. It’s ideal for quickly testing endpoints like APIs, web pages, and resource-heavy routes. With ApacheBench, you can understand how your application behaves under load and optimize accordingly.

Problem Statement

Many developers face the following challenges when preparing web applications for production:

  • Uncertainty about how many concurrent users the server can handle

  • Slow endpoints causing poor user experience under load

  • Difficulty identifying memory or CPU bottlenecks

  • Lack of reproducible load testing metrics

⚠️ Note: ApacheBench simulates load from a single machine, so it’s suitable for small-to-medium testing. For distributed high-volume load, consider tools like k6 or JMeter.

Getting Started with ApacheBench

Installing ApacheBench

On Linux, it often comes preinstalled with Apache HTTP Server. On Ubuntu/Debian:

sudo apt update
sudo apt install apache2-utils
ab -V

For Mac, it’s included with the Apache package or can be installed via Homebrew:

brew install httpd
ab -V

Basic Usage of ApacheBench

The general command structure is:

ab -n <total_requests> -c <concurrent_requests> <URL>

Where:

  • -n → Total number of requests to perform

  • -c → Number of concurrent requests to simulate

  • URL → Full HTTP URL including protocol

Example: Basic Load Test

ab -n 100 -c 10 https://yourdomain.com/shipments/pdf

This command performs 100 requests with 10 concurrent users. You’ll get metrics like:

  • Requests per second
  • Average response time
  • Transfer rate
  • Failed requests

Example: Simulate Higher Load

ab -n 1000 -c 50 https://yourdomain.com/shipments/pdf

Useful for testing queue-based PDF generation endpoints or other heavy processes. Monitor CPU, memory, and queue lengths while performing this test.

Example: POST Requests (API Testing)

ab -n 500 -c 20 -p postdata.json -T 'application/json' https://yourdomain.com/api/orders

Where:

  • -p → Path to a file containing POST payload

  • -T → Content type, e.g., application/json

💡 Related: Load test your Laravel queue-based PDF generation endpoints using ApacheBench for accurate response metrics.

Understanding ApacheBench Metrics

ApacheBench provides a summary of several key performance metrics:

  • Concurrency Level – Number of simultaneous requests

  • Time taken for tests – Total duration of all requests

  • Complete requests – Total requests successfully completed

  • Failed requests – Requests that failed due to server or network errors

  • Requests per second – Average throughput (higher is better)

  • Time per request – Average latency per request

  • Transfer rate – Amount of data served per second

Best Practices for Using ApacheBench

  • Start with a small concurrency and gradually increase to avoid server crashes

  • Monitor CPU, memory, and queue length during tests

  • Use separate machines for high-load testing

  • Combine with Laravel queues for heavy PDF or document endpoints

  • Analyze failed requests carefully to distinguish between network and application issues

Conclusion

ApacheBench is a lightweight, easy-to-use tool that gives developers a clear picture of how their web applications perform under load. While it has limitations for extreme scenarios, it’s perfect for preliminary load testing, identifying bottlenecks, and validating endpoints like PDF or API generation in Laravel.

🚀 Related: Scaling Laravel queue workers with Redis and Supervisor for high-performance PDF generation.
📑 On This Page