Run Laravel commands asynchronously
We at Weengs were not getting the full benefits of Laravel queues because most of our servers are small EC2 instances with only 1 CPU, which means that even if we configure Supervisor to run more than one process it won't make much of a difference as 1 CPU can only run one process at a time.
But we are in 2018 and there's ReactPHP to help us out. We firmly believe we should't be forced to increase our AWS bills in order to have better queue processing power, that's why
Asynq (pronounced async-queue), a little proxy class that makes use of ReactPHP's ChildProcess
component and allows us to call any artisan command and execute them
asynchronously, dramatically increasing our queue processing power. Before
Asynq we had peaks of queued jobs waiting to be processed throughout the day, but not anymore.
composer require weengsapp/asynq
And register the command in
protected $commands = [ \Weengs\Asynq::class ];
Use it as proxy to call any artisan command:
php artisan weengs:asynq 4 queue:work
4 is the number of processes to be run and
queue:work is the signature of the command to be called.
All command options will be forwarded to the proxied command:
php artisan weengs:asynq 4 queue:work --env=development translates to
php artisan queue:work --env=development.
For now we don't forward command arguments, only options are forwarded.
Pull requests are welcome :)