Queues: Two Apps, Two Domains, One Server, One Database
I have just transferred the hosting of two Laravel apps (two separate domains) to run on a single DigltalOcean server, provisioned by Forge: one is an administrative panel and the other is a branded consumer-facing e-commerce site (possibly the first of several distinctly-branded sites). The sites share a common database.
We have historically been using a lot of scheduled commands (fired via cron artisan schedule:run) due to the previous (other hosting provider) server's limitations for long-running process management. I would now like to use queues for many of these tasks instead, now that we have access to Supervisor, Beanstalk, Redis, etc.
Any recommendations/best practices/pitfalls to share? I'm trying to wrap my head around the lines between Laravel applications, domains, and servers when it comes to queues...
Which queue driver would be best? Will one app try to process another's queued jobs (especially with a database driver)? How do I maintain separation between the queue systems (or is that even a concern)?
Quick answer: I've got multiple queues running on a server, and simply distinguish the apps with an environment check (so check the domain, load the correct config). Artisan can detect this domain (php artisan env will show you) and handle the correct queue.
It's a Laravel 4.2 app, but bootstrap/start.php and something like this:
$env = $app->detectEnvironment(function()
{
if (gethostname() == "blah") {
if (isset($_SERVER['HTTP_HOST'])) {
switch($_SERVER['HTTP_HOST']) { ...
You return a value from there based on whatever criteria you need to use to distinguish between sites.
Laravel queue workers (the PHP processing queue jobs) is just an instance of an application on the CLI (cd ~myapp.com && php artisan queue:listen ...).
So, each app can be configured to listen to a queue (preferably a separate queue per app). Then each app can add jobs to its own queue.
In that way, they jobs are segmented between apps - each app only puts job in and reads new job from their own queue.
This is usually just as simple as changing the name of the queue in the laravel queue config file. Forge's use of beanstalkd for the queue (which can handle having more than one named queue, or "pipe" in beanstalkd's language) and Supervisord for the laravel workers (queue:listen command) should work great for that.
So, in that setup, you won't have one queue worker listening for jobs from both applications - so you won't need any code deciding which domain was used. (I'm assuming they are two separate applications as you said!)