DEV Community

Cover image for Effortless Laravel Performance Testing — Without Leaving PHP
Islam A-Elwafa
Islam A-Elwafa

Posted on • Originally published at php.volt-test.com

Effortless Laravel Performance Testing — Without Leaving PHP

When your Laravel app hits real traffic, will it fly… or will it fall over?

Most load-testing tools make you jump through hoops — learn a new scripting language, spin up external services, or fight with configs that feel like they belong to another ecosystem.

That’s why I built the Laravel Performance Testing package:

a native, PHP-first way to run load and stress tests right inside your Laravel project — powered by the Volt Test PHP SDK.

You write your tests in plain PHP, keep them version-controlled with your codebase, and run them with a single Artisan command. No context-switching. No external scripts. Just Laravel, PHP, and the performance insights you need before your users find the bottlenecks.

Effortless Laravel Performance Testing with Volt Test PHP SDK

Why I Created This Package

About a month ago, I released this package to make performance testing in Laravel:

  • Easier – no external scripts or frameworks to learn.
  • Native – tests live inside your Laravel project.
  • Flexible – from simple single-URL load tests to complex multi-step scenarios.

✨ Features

  • Laravel-friendly integration – Works seamlessly with routes, middleware, and config.
  • Artisan commands – Generate and run tests directly from the CLI.
  • Automatic route discovery – Quickly build test scenarios from your existing routes.
  • Variable extraction – Reuse cookies, headers, JSON fields, and HTML values between steps.
  • Data-driven testing – Feed test data from CSV files for realistic simulations.
  • Detailed metrics – Success rate, RPS, average latency, P95 latency, and more.
  • Report storage – Save test results for later analysis.

🚀 Installation

composer require volt-test/laravel-performance-testing
Enter fullscreen mode Exit fullscreen mode

Publish the configuration file:

php artisan vendor:publish --tag=volttest-config
Enter fullscreen mode Exit fullscreen mode

This creates config/volttest.php where you can tweak settings like default virtual users, duration, and report paths.


⚡ Quick Start

Run a quick performance test without writing any code:

php artisan volttest:run https://example.com/api/login --users=100 --method=POST --body='{"email":"test@example.com","password":"secret"}'
Enter fullscreen mode Exit fullscreen mode

Or, create a reusable test class:

php artisan volttest:make ExampleTest
Enter fullscreen mode Exit fullscreen mode

This generates app/VoltTests/ExampleTest.php:

namespace App\VoltTests;

use VoltTest\Laravel\Contracts\VoltTestCase;
use VoltTest\Laravel\VoltTestManager;

class ExampleTest implements VoltTestCase
{
    public function define(VoltTestManager $manager): void
    {
        $manager->scenario('ExampleTest')
            ->step('Visit Home Page')
            ->get('https://example.com')
            ->validateStatus('success', 200);
    }
}
Enter fullscreen mode Exit fullscreen mode

Run it with:

php artisan volttest:run ExampleTest --users=50 --duration=30
Enter fullscreen mode Exit fullscreen mode

🎯 Route-Based Test Generation

Skip manual coding by generating tests from your Laravel routes:

# Include all routes
php artisan volttest:make ApiTest --routes

# Filter by pattern
php artisan volttest:make ApiTest --routes --filter="api/*"

# Only GET routes
php artisan volttest:make ApiTest --routes --method=GET

# Only authenticated routes
php artisan volttest:make ApiTest --routes --auth

# Interactive selection
php artisan volttest:make ApiTest --routes --select
Enter fullscreen mode Exit fullscreen mode

📊 Data-Driven Testing

Simulate realistic usage with CSV files.

users.csv

name,email,password
John Doe,user1@example.com,password123
Jane Smith,user2@example.com,password456
Enter fullscreen mode Exit fullscreen mode

Test definition:

$manager->scenario('RegisterTest')
    ->dataSource('users.csv')
    ->step('Register User')
    ->post('/register', [
        'name' => '${name}',
        'email' => '${email}',
        'password' => '${password}',
    ]);
Enter fullscreen mode Exit fullscreen mode

🔍 Extract & Reuse Values

CSRF token from HTML

$scenario->step('Get Login Page')
    ->get('/login')
    ->extractCsrfToken('csrf_token');

$scenario->step('Submit Login')
    ->post('/login', [
        '_token' => '${csrf_token}',
        'email'  => 'user@example.com',
        'password' => 'secret',
    ]);
Enter fullscreen mode Exit fullscreen mode

JSON field

$scenario->step('Get User')
    ->get('/api/user')
    ->extractJson('user_id', 'data.id');
Enter fullscreen mode Exit fullscreen mode

Header

$scenario->step('Get Token')
    ->get('/auth')
    ->extractHeader('Authorization', 'Bearer ${token}');
Enter fullscreen mode Exit fullscreen mode

📈 Analyzing Results

After running a test, you’ll see metrics such as:

  • ✅ Success rate
  • ⚡ Requests per second (RPS)
  • ⏱ Average & P95 latency
  • ⌛ Duration
  • ❌ Errors

If save_reports is enabled, detailed reports are stored in:

storage/volttest/reports
Enter fullscreen mode Exit fullscreen mode

🏁 Conclusion

With Laravel Performance Testing powered by the Volt Test PHP SDK, you can:

  • Keep performance tests inside your Laravel project.
  • Run them with one Artisan command.
  • Get actionable performance metrics before your users notice slowdowns.

📚 Docs: Laravel Performance Testing on GitHub

📦 Volt Test PHP SDK: php.volt-test.com

💡 Pro Tip: Integrate Volt-Test into your CI pipeline to catch performance regressions before they hit production.

Top comments (0)