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
Adam Mateusz Brożyński | Sciencx (2024-06-30T23:28:56+00:00) Cronless queue:work in Laravel executed in background. Retrieved from https://www.scien.cx/2024/06/30/cronless-queuework-in-laravel-executed-in-background/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.