Home  >  Q&A  >  body text

laravel5.1 asynchronous queue problem

1. Modify the configuration in the queue in the config folder as:

'default' => env('QUEUE_DRIVER', 'database'),

    /*
    |--------------------------------------------------------------------------
    | Queue Connections
    |--------------------------------------------------------------------------
    |
    | Here you may configure the connection information for each server that
    | is used by your application. A default configuration has been added
    | for each back-end shipped with Laravel. You are free to add more.
    |
    */

    'connections' => [

        'sync' => [
            'driver' => 'sync',
        ],

        'database' => [
            'driver' => 'database',
            'table'  => 'jobs',/*在数据库的配置中有定义数据表前缀为ksb_,这里不知是否需要补全前缀*/
            'queue'  => 'default',
            'expire' => 60,
        ],
        ……………………

2. Create a queue table

php artisan queue:table
php artisan migrate

3. Create queue task class

php artisan make:job CollectionBook

4. Push the task to the queue

$job = (new CollectionBook(3565))->onQueue('collectionbook')->delay(60);
dispatch($job);

5. Background monitoring

php artisan queue:work --queue=collectionbook --daemon --sleep=3 --tries=3

Page for running push tasks
It is found that the queue is run synchronously and is not written into the queue task table. How to solve this?


The above problem has been solved thanks to the answers from the students on the 1st floor. Now there is a second question

Run in the website root directory (/home/wwwroot/kshuba/)

php artisan queue:work --queue=collectionbook --daemon --sleep=3 --tries=3

The queue task in the database is consumed
At this time, if you check ps artisan, you will see that the process is:

root 2287 2144 9 18:30 pts/0 00:00:02 php artisan queue:work --queue=collectionbook --daemon --sleep=3 --tries=3

But when the ssh client was disconnected, it was found that the process had disappeared
At this time, supervisor was used to monitor the process

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/wwwroot/kshuba/artisan queue:work --queue=collectionbook --sleep=3 --tries=3 --daemon
autostart=true
autorestart=true
user=forge
numprocs=8
redirect_stderr=true

Start supervisor and query
The result is monitoring

laravel-worker-collectionbook RUNNING pid 2271, uptime 0:00:02

ps artisan will see the process as:

root 2300 2144 9 18:30 pts/0 00:00:02 php /home/wwwroot/kshuba/artisan queue:work --queue=collectionbook --daemon --sleep=3 --tries= 3

The problem is that the queue tasks in the query database have not been consumed
In addition, if you run it in the root directory of the server

php /home/wwwroot/kshuba/artisan queue:work --queue=collectionbook --daemon --sleep=3 --tries=3

Queue tasks cannot be consumed either
Try changing the supervisor’s command to:

php artisan queue:work --queue=collectionbook --sleep=3 --tries=3 --daemon

It is found that supervisor> status will prompt: BACKOFF Exited too quickly (process log may have details)
The monitoring cannot be started, how to solve it?


My own configuration is missing -- the problem has been solved!

给我你的怀抱给我你的怀抱2735 days ago843

reply all(1)I'll reply

  • 为情所困

    为情所困2017-05-16 16:55:47

    Is .env configured?

    reply
    0
  • Cancelreply