- How do I run stress tests without blocking php artisan serve in Laravel?
- Use the `StressTestRunner` class with `startBackground()`. It spawns Guzzle requests in a subprocess, avoiding deadlocks with Laravel’s single-threaded dev server. Poll results via a temporary JSON file using the generated job ID.
- Does laravel-stress work with multi-threaded servers like Nginx or Apache?
- Yes. The package includes an in-process fallback mode (`run()` method) that works seamlessly with multi-threaded servers, ensuring compatibility across dev and production environments.
- What Laravel versions does this package support?
- Check the package’s `composer.json` for exact version requirements, but it’s designed for modern Laravel (8.x+) and leverages Guzzle, which is widely supported. Ensure your Laravel version aligns with Guzzle’s compatibility.
- Can I integrate stress testing into my CI/CD pipeline?
- Yes, but results must be manually validated since the package doesn’t include built-in assertions. Use PHPUnit/Pest hooks to trigger tests and parse JSON output for custom validation logic in your pipeline.
- How do I handle sensitive headers (e.g., API keys) in stress tests?
- Pass sensitive headers via environment variables or encrypted storage (e.g., Laravel’s `config/stress.php`). Avoid hardcoding credentials in test configurations to prevent leaks.
- What if I need higher concurrency than Guzzle’s default (5)?
- The package uses Guzzle’s concurrency limits, which may not scale for high-load scenarios. For advanced needs, consider replacing subprocesses with Laravel queues or a custom solution like `reactphp` for distributed testing.
- How do I access stress test results programmatically?
- For background jobs, poll the temporary JSON file using the job ID (e.g., `sys_get_temp_dir() . '/lb_st_res_' . $jobId . '.json'`). For synchronous runs, the `run()` method returns a structured JSON object with metrics like throughput, error rates, and timing percentiles.
- Are there alternatives to laravel-stress for Laravel load testing?
- For CI/CD-focused testing, consider `laravel-shift/load-testing` or `spatie/laravel-load-testing`. For production-grade tools, use dedicated solutions like Locust or k6, though they require separate infrastructure.
- How do I clean up temporary result files after tests?
- The package doesn’t auto-delete files, so manually remove them after processing (e.g., `unlink($resultFile)`). For shared environments, configure a custom temp directory (e.g., `storage/app/stress-results`) to avoid permission issues.
- Can I monitor stress test results in real-time (e.g., Slack alerts)?
- No, the package doesn’t include alerting. Extend it by parsing JSON results in a Laravel event listener or queue job, then trigger notifications via services like Slack or Datadog using Laravel’s notification system.