I want my laravel queue:work to keep running on a shared hosting, this is a shared hosting (am not on a VPS) I can't install anything because almost all online sources when I was searching for this suggest installing supervisor. So basically I thought I could just create a cron job that checks if queue is not running and starts it, any help on how to go about this because am kinda stuck, thanks.
P.S. Am on a Linux server and Laravel 5.3
As you mentioned you are using shared hosting, You follow the below steps.
Step 1.
you need to setup your queue driver as database
Step 2
you need to setup a cron job with with the following command
php /path/to/application/artisan queue:work --queue=high,default
.
You can give a try. I hope it will work.
One more solution (I solved same problem in this way). You can make script like this:
# getting running processes with name "queue:work"
QUEUE_STATUS=$(ps aux | grep "queue:work")
# check is queue:work started, if no, start it
if $( echo $QUEUE_STATUS | grep --quiet 'artisan queue:work')
then
exit;
else
php ~/public_html/artisan queue:work
fi
and run it in CRON. I run every 10 min.
I figured a hack to accomplish this
On file Illuminate\Queue\Worker.php
my current laravel version (5.3) is on line 151; on function runNextJob($connectionName, $queue, WorkerOptions $options)
add else
as below
if ($job) {
return $this->process(
$connectionName, $job, $options
);
} else {
$this->stop();
}
Now create cron job that will run the number of times you like with command php artisan queue:work
the moment the queue is exhausted, it will exit (but should be frequent as the process exists)
UPDATE: Using task schedular with withoutOverlapping()
prevents further calls of the command if its already running, so this is a better option considering the previous one is a change you have to make everytime you composer install
or composer update
This is the solution that worked for me after searching for days.
flock -n /tmp/latavel_queues.lockfile /usr/bin/php /path/to/laravel/artisan queue:listen
See https://laracasts.com/discuss/channels/servers/database-queue-on-shared-hosting
the best way is to set followin command on your tasks of panel (I'm using plesk control panel, it makes me able to set task there)
php artisan queue:work --once
Note: in my shared host, I must set following values because of their server configuration:
- php: /opt/plesk/php/7.2/bin/php -q
- artisan: /var/www/vhosts/t4f.ir/httpdocs/artisan
- my command: then I should write the command
so, the result would be like this:
/opt/plesk/php/7.2/bin/php -q /var/www/vhosts/t4f.ir/httpdocs/artisan queue:work --once
there is another option for runtime which I set to Cron type with value of: * * * * * which means, every minute this code will be executed. as I used --once in end of my commad, once it execute the command and job has been finished, it will be terminated. regarding to concurrent execution, I'm not worried about beacuase it's handling in queueing system and it's responsibility of this system.
来源:https://stackoverflow.com/questions/46141652/running-laravel-queuework-on-a-shared-hosting