{"id":13037,"date":"2020-05-01T15:34:48","date_gmt":"2020-05-01T15:34:48","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=13037"},"modified":"2021-11-08T10:36:38","modified_gmt":"2021-11-08T10:36:38","slug":"how-to-handle-long-processing-asynchronous-request-through-queue-using-database-in-laravel","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-handle-long-processing-asynchronous-request-through-queue-using-database-in-laravel\/","title":{"rendered":"How to Handle Long processing asynchronous request through Queue using database in Laravel?"},"content":{"rendered":"\n<p>in this blog you are going to see that whenever you want to send email to multiple user then your view page takes a lot of time. so how can you decrease the load time and send email in background.<\/p>\n\n\n\n<p>first of all you should create a folder Jobs under app and add two files eg. job.php and MailJob.php and now see both files code and add it to your files as well.<\/p>\n\n\n\n<p>create a file to this location (<strong>app\/Jobs\/job.php<\/strong>) and put below codes in it.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/cmschandan\/fe2a848ce55b3ddb980b1d4e9ce3ac1d.js\"><\/script>\n\n\n\n<p>Now create another file name <strong>MailJob.php<\/strong> and put below code:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/cmschandan\/f5fa37d8ac1d9c0052b7f59e7c1ce61b.js\"><\/script>\n\n\n\n<p>and add below code to your SampleMail.php (app\/Mail) location<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/cmschandan\/3a77793b2ab7742d8914854082b94862.js\"><\/script>\n\n\n\n<p>now change some code in your <strong>store<\/strong> function of your <strong>Controller.php<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/cmschandan\/67e73816e1c9e39fae084be5e3f8df79.js\"><\/script>\n\n\n\n<p>now you should check you have a jobs table in your database. for this you should create a migration by putting below command<br><em>php artisan queue:table<\/em> <br>For more reference see this article <a rel=\"noreferrer noopener\" href=\"https:\/\/www.larashout.com\/laravel-queues-step-by-step-guide\" target=\"_blank\">Click Here<\/a> <\/p>\n\n\n\n<p>Now you should run a command in terminal for processing queues:<br><em><strong>php artisan queue:work <\/strong><\/em><br>after this whenever you click on submit button in your form your form will submitted within 2 to 3 second and your email will process in the background and your request of email should be partially stored in jobs table.<\/p>\n\n\n\n<p>for more details you can refer below articles:<br>Click Here: <a rel=\"noreferrer noopener\" href=\"https:\/\/laravel.com\/docs\/5.1\/queues\" target=\"_blank\">reference of queue<\/a><\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_26113\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_68731\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_26113\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>in this blog you are going to see that whenever you want to send email to multiple user then your view page takes a lot of time. so how can you decrease the load time and send email in background. first of all you should create a folder Jobs under app and add two files&#8230;<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5201],"tags":[6072,5355,5203,5978,5957,6071],"class_list":["post-13037","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-asynchronous","tag-database","tag-laravel","tag-laravel-5-5","tag-mail","tag-queue"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/13037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=13037"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/13037\/revisions"}],"predecessor-version":[{"id":24854,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/13037\/revisions\/24854"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=13037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=13037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=13037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}