andrey_mireichyk/roadrunner-bundle
Install the Bundle:
composer require andrey_mireichyk/roadrunner-bundle
If not using Symfony Flex, manually register the bundle in config/bundles.php:
return [
// ...
Baldinof\RoadRunnerBundle\BaldinofRoadRunnerBundle::class => ['all' => true],
];
Fetch RoadRunner Binary:
vendor/bin/rr get --location bin/
Configure RoadRunner: Copy default config files:
cp vendor/andrey_mireichyk/roadrunner-bundle/.rr.* .
Start RoadRunner:
bin/rr serve
Access your app at http://localhost:8080.
Replace Symfony’s php bin/console server:run with RoadRunner for production-like performance during development:
bin/rr serve -c .rr.dev.yaml # Use dev config for auto-reload
Kernel Reboot Strategy:
Configure kernel reboot behavior in config/packages/baldinof_road_runner.yaml:
baldinof_road_runner:
kernel_reboot:
strategy: on_exception # Default; reboot only on uncaught exceptions
allowed_exceptions:
- Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
strategy: always for stateless services (e.g., APIs).Symfony\Contracts\Service\ResetInterface for stateful services.Middleware Integration:
Add custom middleware (PSR-15 or IteratorMiddlewareInterface) in config/packages/baldinof_road_runner.yaml:
baldinof_road_runner:
middlewares:
- App\Middleware\LoggingMiddleware
- App\Middleware\CachingMiddleware
Note: Middlewares run outside Kernel::handle(). Use IteratorMiddlewareInterface for post-response logic (e.g., logging).
Metrics Collection:
Enable metrics in config/packages/baldinof_road_runner.yaml:
baldinof_road_runner:
metrics_enabled: true
Configure .rr.yaml:
metrics:
address: localhost:2112
collect:
app_requests_total:
type: counter
help: "Total HTTP requests."
Inject Spiral\RoadRunner\MetricsInterface in controllers:
public function index(MetricsInterface $metrics): Response {
$metrics->add('app_requests_total', 1);
return new Response('OK');
}
Database Connection Handling:
For Doctrine, install symfony/proxy-manager-bridge to handle reconnections:
composer require symfony/proxy-manager-bridge
Configure session storage in the database using shapecode/doctrine-session-handler-bundle:
composer require shapecode/doctrine-session-handler-bundle
getsentry/sentry-symfony is installed.framework.sessions.enabled is true.clear() on managers post-request to avoid connection leaks.blackfire/php-sdk. Ensure nyholm/psr7 is installed if using sensio/framework-extra-bundle.Kernel State Persistence:
strategy: always or whitelist exceptions in allowed_exceptions.Middleware Initialization:
Metrics Injection:
metrics_enabled: false, MetricsInterface injects a NullMetrics instance. Check config before recording:if ($metrics instanceof Spiral\RoadRunner\NullMetrics) {
return $response;
}
Dev Mode Quirks:
VarDumper dumps won’t appear in HTTP responses. Use bin/console server:dump or the profiler..rr.dev.yaml and bin/rr serve -c .rr.dev.yaml.PSR-7 Factories:
php-http/discovery. Ensure nyholm/psr7 or symfony/psr-http-message-bridge is installed.TCP Relay Configuration:
Spiral\Goridge\RelayInterface in services.yaml for custom transports (e.g., TCP sockets):services:
Spiral\Goridge\RelayInterface:
class: Spiral\Goridge\SocketRelay
arguments: ['localhost', 7000]
Update .rr.yaml:
http:
workers:
relay: "tcp://localhost:7000"
Worker Logs: Check RoadRunner logs for errors:
bin/rr logs
Or tail the log file (default: var/log/roadrunner.log).
Connection Issues:
Doctrine reconnection errors may crash workers. Use symfony/proxy-manager-bridge and configure kernel_reboot to handle failures gracefully.
Middleware Debugging:
Log middleware execution in IteratorMiddlewareInterface:
public function __invoke(ServerRequestInterface $request, callable $next) {
error_log('Middleware executed');
$response = $next($request);
error_log('Response sent');
return $response;
}
Metrics Verification: Validate metrics collection with:
curl http://localhost:2112/metrics
Or use Prometheus tools like promtool.
Custom Kernel Reboot Logic:
Extend Baldinof\RoadRunnerBundle\Worker\Worker (internal) or implement Symfony\Contracts\Service\ResetInterface for stateful services.
Relay Transport:
Replace Spiral\Goridge\RelayInterface for custom transports (e.g., gRPC, WebSockets).
Post-Response Hooks:
Use IteratorMiddlewareInterface for logic after response sending (e.g., analytics, cleanup).
Metrics Customization:
Extend Spiral\RoadRunner\MetricsInterface or add new metric types in .rr.yaml:
metrics:
collect:
custom_metric:
type: gauge
help: "Custom application metric."
How can I help you explore Laravel packages today?