Cronless queue:work in Laravel executed in background

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 en…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Cronless queue:work in Laravel executed in background." Adam Mateusz Brożyński | Sciencx - Sunday June 30, 2024, https://www.scien.cx/2024/06/30/cronless-queuework-in-laravel-executed-in-background/
HARVARD
Adam Mateusz Brożyński | Sciencx Sunday June 30, 2024 » Cronless queue:work in Laravel executed in background., viewed ,<https://www.scien.cx/2024/06/30/cronless-queuework-in-laravel-executed-in-background/>
VANCOUVER
Adam Mateusz Brożyński | Sciencx - » Cronless queue:work in Laravel executed in background. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/30/cronless-queuework-in-laravel-executed-in-background/
CHICAGO
" » Cronless queue:work in Laravel executed in background." Adam Mateusz Brożyński | Sciencx - Accessed . https://www.scien.cx/2024/06/30/cronless-queuework-in-laravel-executed-in-background/
IEEE
" » Cronless queue:work in Laravel executed in background." Adam Mateusz Brożyński | Sciencx [Online]. Available: https://www.scien.cx/2024/06/30/cronless-queuework-in-laravel-executed-in-background/. [Accessed: ]
rf:citation
» Cronless queue:work in Laravel executed in background | Adam Mateusz Brożyński | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.