This content originally appeared on DEV Community and was authored by Adam Mateusz Brożyński
There are some approaches how to execute queue:work but I found them useless. Here is a solution for most shared hostings that will not require additional route, remotely visiting website, shell or cron access. It will require only PHP exec
function enabled and php-cli
installed on server:
$cmd = 'cd '.base_path().' && /usr/bin/php artisan queue:work --stop-when-empty';
$out = base_path().'/queue.log';
$pid = base_path().'/queue.pid';
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $out, $pid));
If we want to use it in frontent we can add things like:
- lock file and lock file check
- timestamp check (we can do it using database or just
filemtime
) to control execution rate
This content originally appeared on DEV Community and was authored by Adam Mateusz Brożyński