Running laravel queue:work on a shared hosting

后端 未结 6 1917
你的背包
你的背包 2020-12-18 01:45

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 on

相关标签:
6条回答
  • 2020-12-18 02:01

    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

    0 讨论(0)
  • 2020-12-18 02:02

    Try adding two cron jobs:

    1. To clear cache:
    /usr/local/bin/php /home/<path-to-project>/artisan cache:clear
    
    1. To run the scheduler
    /usr/local/bin/php /home/<path-to-project>/artisan schedule:run
    

    Also, make sure that your app\Console\Kernel.php is having something like

    protected function schedule(Schedule $schedule)
        {
            $schedule->command('queue:work --tries=3')
                ->cron('* * * * *')
                ->withoutOverlapping(5);
        }
    

    Remove the first job (the one to remove cache) if the queue starts working

    0 讨论(0)
  • 2020-12-18 02:08

    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

    0 讨论(0)
  • 2020-12-18 02:12

    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:

    1. php: /opt/plesk/php/7.2/bin/php -q
    2. artisan: /var/www/vhosts/t4f.ir/httpdocs/artisan
    3. 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.

    0 讨论(0)
  • 2020-12-18 02:14

    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.

    0 讨论(0)
  • 2020-12-18 02:21

    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.

    0 讨论(0)
提交回复
热议问题