Open greggailly opened 3 years ago
Hi! Thank you for trying this bundle 🙂
Can you give me an example of code that shows how your are injecting the URL?
To manage multi tenancy on Symfony side we are using what is described in the following article: https://symfony.com/doc/current/configuration/override_dir_structure.html More specifically we inject at runtime a parameter inside the container using the configureContainer method in the Kernel:
// $url = custom db url created after having read file specific to each "client"
$container->parameters()->set('db_url', $url);
So we consider the only "dynamic" part of our multi tenancy is handle by the container when being build so we use the getCacheDir method to make sure that on each request, cache corresponding to the correct client is loaded and the the db_url parameter in the container is OK.
public function getCacheDir()
{
$request = Request::createFromGlobals();
$this->client = $request->headers->get('x-client');
return "/server/data/cache/" . $this->client . "/" . $this->environment;
}
Process is simplified but basically we get the client directory from a header added by our reverse proxy and make sure that the container is loaded for this specific client.
That being said we need to have a new Kernel booted for each request otherwise the cache fetched could be from a previous request.
So at the end for the moment we ended up writing our own RR worker. It boots the kernel inside the while loop to make sure it is created depending on the request.
Hi, We are trying to use roadrunner on a multi tenant symfony project. Multi-tenancy is handled by the kernel, we inject database url dynamically depending on the request. This works fine with the PHP dev server however we cannot get it to work with roadrunner (missing database url). I guess this comes from the fact that the kernel is not always rebooted. So we tried to set the strategy to always but this didn't have any effect. Furthermore we tried to add
$this->kernel->reboot(null);
at the beginning of the while loop in the Worker.php to make sure the container is rebuild but didn't seem to solve our problem either. Does anybody have any ideas on how to handle this ? Thanks in advance !