PHP code example of laramint / laravel-stress

1. Go to this page and download the library: Download laramint/laravel-stress library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laramint / laravel-stress example snippets


use LaraMint\LaravelStress\StressTestRunner;

$runner = new StressTestRunner;

// Background (non-blocking) — returns a job ID to poll
$jobId = $runner->startBackground([
    'method'      => 'GET',
    'url'         => 'http://127.0.0.1:8000/api/users',
    'count'       => 50,
    'concurrency' => 5,
    'timeout'     => 10,
    'headers'     => ['Authorization' => 'Bearer token'],
    'body'        => null,
]);

// Poll the result file written by the subprocess
$resultFile = sys_get_temp_dir() . '/lb_st_res_' . $jobId . '.json';
// { "status": "running" }  →  keep polling
// { "status": "done", "result": { ... } }  →  done

// Synchronous (blocking) — works with multi-threaded servers
$result = $runner->run([...]);