Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property POMO_FileReader::$is_overloaded is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 26

Deprecated: Creation of dynamic property POMO_FileReader::$_pos is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 29

Deprecated: Creation of dynamic property POMO_FileReader::$_f is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 160

Deprecated: Creation of dynamic property MO::$_gettext_select_plural_form is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/translations.php on line 292

Deprecated: Creation of dynamic property POMO_FileReader::$is_overloaded is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 26

Deprecated: Creation of dynamic property POMO_FileReader::$_pos is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 29

Deprecated: Creation of dynamic property POMO_FileReader::$_f is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/streams.php on line 160

Deprecated: Creation of dynamic property MO::$_gettext_select_plural_form is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/pomo/translations.php on line 292

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-block-type.php on line 391

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-block-type.php on line 391

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-term-query.php on line 1118

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home3/achieve/public_html/knowledgebase/wp-includes/class-wp-term-query.php on line 1118

Warning: Cannot modify header information - headers already sent by (output started at /home3/achieve/public_html/knowledgebase/wp-includes/wp-db.php:760) in /home3/achieve/public_html/knowledgebase/wp-includes/feed-rss2.php on line 8
Queue – Knowledge http://knowledge.achieveee.com Wed, 19 Apr 2017 14:43:38 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.7 http://knowledge.achieveee.com/wp-content/uploads/2016/05/cropped-favicon-32x32.png Queue – Knowledge http://knowledge.achieveee.com 32 32 Create Queue Listener in Laravel 5 http://knowledge.achieveee.com/knowledge_base/create-queue-listener-in-laravel-5/ http://knowledge.achieveee.com/knowledge_base/create-queue-listener-in-laravel-5/#respond Tue, 10 May 2016 10:23:27 +0000 http://knowledge.achieveee.com/?post_type=knowledge_base&p=2467 Laravel has an unified API for various queue back-ends. Queue allows us to process the time-consuming task faster, such as sending email which ultimately speed ups the web applications.

Steps to follow for creating Queue Listener:

  1. Install Supervisor

    Supervisor will automatically restart the queue if fails or stop working. To install Supervisor on Linux based system, use below command:

    sudo apt-get install supervisor

     

  2. Create ‘/etc/supervisor/conf.d/laravel-worker.conf‘ and paste the below code into it

    [program:laravel-worker]
    user=user_name
    process_name=%(program_name)s_%(process_num)02d
    command=php application_path/artisan queue:listen --sleep=3 --tries=3
    directory=application_path
    autostart=true
    autorestart=true
    numprocs=10
    redirect_stderr=true
    stdout_logfile=application_path/storage/logs/worker.log

    where,
    user_name: Your machine user
    application_path: Full path to your application

  3. Start the processes using following commands

    sudo supervisorctl reread
    sudo supervisorctl update
    sudo supervisorctl start laravel-worker:*

 

Now your queue listener is ready, let’s configure Laravel by following steps:


Step
1:

Set QUEUE_DRIVER=database in .env file

Step 2:
Navigate to queue.php file and check whether the table name and other settings for queue are present in database section

Step 3:
Run this command to migrate queue table in database

php artisan queue:table
php artisan queue:failed-table
php artisan migrate

 

You are ready for sending email through queue. Just replace Mail::send with Mail::queue or Mail::later

Final Steps:
Start and stop the following processes one by one to make Supervisor listen everytime (perform only if Supervisor doesn’t start listening automatically)

php artisan queue:listen
php artisan queue:work --daemon


*Note
:

1. Add ‘APP_URL‘ in .env file as per the accessible domain for application. If you’re using ‘url()‘ function in email which is queued, not adding ‘APP_URL‘ will generate a localhost URL.

2. While passing data to views when using Mail::queue or Mail::later the data isn’t accessible as expected. This happens when you’re passing an object or eloquent object and not as arrays. To make this work with queue you have to serialize the $eloquentObject first and later unserialize it in the view.

Mail::queue('emails.hello', serialize($data), function($message) {
...
});

Add this on top of view file:

{{-- */unserialize($data);/* --}}
]]>
http://knowledge.achieveee.com/knowledge_base/create-queue-listener-in-laravel-5/feed/ 0