Download the PHP package fluffydiscord/roadrunner-symfony-bundle without Composer
On this page you can find all versions of the php package fluffydiscord/roadrunner-symfony-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fluffydiscord/roadrunner-symfony-bundle
More information about fluffydiscord/roadrunner-symfony-bundle
Files in fluffydiscord/roadrunner-symfony-bundle
Package roadrunner-symfony-bundle
Short Description Roadrunner runtime for Symfony
License MIT
Informations about the package roadrunner-symfony-bundle
RoadRunner Runtime for Symfony
Yet another runtime for Symfony and RoadRunner.
Installation
Usage
- Define the environment variable
APP_RUNTIME
in.rr.yaml
and set uprpc
plugin:
.rr.yaml
Don't forget to add the RR_RPC
to your .env
:
- Replace
MicroKernelTrait
withRoadRunnerMicroKernelTrait
in yourKernel.php
:
The default behavior of Symfony's kernel is to reset your services before request is handled and slows down the initial reaction time.
When new request arrives | Your app | After response was sent back | |
---|---|---|---|
Symfony | does a reset, if something fails here, request may be lost | waits for reset to be done, then handles your request | |
RoadRunnerBundle | immediately handles your request | does a reset |
You might want to manually refresh Doctrine connections before each request is handled
you are using Mysql
, MariaDB
or other database that cannot handle long/persistent
connection. For this, it's up to you to create event listener for WorkerRequestReceivedEvent
Configuration
fluffy_discord_road_runner.yaml
Running behind a load balancer or a proxy
If you want to use REMOTE_ADDR
as trusted proxy, replace it with private_ranges
instead
or else your trusted headers will not work.
Symfony is using the $_SERVER['REMOTE_ADDR']
to find out the proxy address,
but in the context of RoadRunner, $_SERVER
contains only environment
variables and the REMOTE_ADDS
is missing.
Response/file streaming
Build-in full support for Symfony's BinaryFileResponse
and StreamedJsonResponse
. The StreamedResponse
needs one little
change to be fully streamable - you have to change the callback
to a \Generator
, replacing all echo
with yield
. Look at the example:
Sentry
Built in support for Sentry. Just install & configure it as you normally do.
Centrifugo (websockets)
To enable Centrifugo you need to add roadrunner-php/centrifugo
package.
Bundle is using Symfony's Event dispatcher. You can create event listener for any event extending FluffyDiscord\RoadRunnerBundle\Event\Centrifugo\CentrifugoEventInterface
:
ConnectEvent
required :)InvalidEvent
PublishEvent
RefreshEvent
RPCEvent
SubRefreshEvent
SubscribeEvent
Example usage:
Be aware that if you do not set any response, bundle will send DisconnectResponse
back by default.
Developing with Symfony and RoadRunner
- If possible, stop using lazy loading in your services, inject services immediately. Lazy loaded services might introduce memory leaks and make your services slower to initialize when requests arrive.
- Do not use/create local class/array caches in your services, only if you know, what you are doing. Try to make them stateless or use ResetInterface to clean up before each request, so state is not being shared.
- Symfony forms might leak data across requests due to caching, see section bellow.
- Simplify your
User
session serialization by taking advantage ofEquatableInterface
and a custom de/serialization logic. This will prevent errors because of detached Doctrine entities and, as a side bonus, will speed up loading user from sessions.
OptionsResolver (Forms)
Symfony caches OptionsResolver::setDefaults() calls, so they resolve only once for current worker when someone uses them for the first time.
This may lead to sharing sensitive information across requests in the context of a single worker, if you do not use defaults correctly.
Consider this Form, which has major flaw that will leak user email to subsequent requests that worker receives.
You should really use only static/stateless default values
and dynamic options should be passed when
OptionsResolver
is used, or form is being created, eg:
Debugging (recommendations)
With RoadRunner you cannot simply dump and die, because nothing will be printed. I would like to introduce Buggregator to work around that. As a bonus it can also work as a mailtrap or testing Sentry locally
Credits
Inspiration taken from existing solutions like Baldinof's Bundle and Nyholm's Runtime
All versions of roadrunner-symfony-bundle with dependencies
nyholm/psr7 Version ^1.8
spiral/roadrunner Version ^v2024
symfony/dependency-injection Version ^7.0 || ^6.4 || ^5.4
symfony/http-kernel Version ^7.0 || ^6.4 || ^5.4
symfony/psr-http-message-bridge Version ^7.0 || ^6.4 || ^2.3
symfony/runtime Version ^7.0 || ^6.4 || ^5.4
symfony/framework-bundle Version ^7.0 || ^6.4 || ^5.4
symfony/event-dispatcher Version ^7.0 || ^6.4 || ^5.4
spiral/roadrunner-worker Version ^v3
spiral/roadrunner-http Version ^v3
spiral/roadrunner-cli Version ^v2.6