Laravel 5.8 – From The Ground Up - Laravel 5.8 Tutorial From Scratch – e30 – queue:work In The Background

Education, Programming

Laravel 5.8 – From The Ground Up

52 Lessons

Laravel 5.8 Tutorial From Scratch – e30 – queue:work In The Background

in the previous episode we talked about running our cue worker in our terminal while we are developing however the question did arise fairly quickly from

one of you asking well how do I run that in the background I don't want to have to run that in the foreground so we're gonna do a quick lesson today just to show you how we can put that in the

background and still maintain our output and being able to log that to a file so let's start off right where we left in the previous lesson we were running PHP artisan cue work and of course that

stays right there as you can tell it is just waiting for a job to come in let's give it a job let's go to Chrome add a new customer give it an email add customer and sure enough we are

processing our job we know our job takes roughly about 10 seconds because we're using that sleep timer on it and there we go all right so our job processed we head back and we have our email all

right so everything is working exactly as expected I'm going to hit ctrl C to exit out of that process and to put that command in the background it's actually quite simple all you have to do is add

an ampersand at the end so exactly the same command except at the end use that space and then ampersand and when you run that you see that now we have our prompt back and we have this five digit

here this is called a process ID all right so this is process ID 2900 eight you don't really have to remember that I'll show you how to look that up later on now right now that is running it is

listening for jobs to come in and to prove that we can run jobs and we see here we have a process that is running and the process running is PHP artisan queue work so let's add another customer

any user will do test a test add customer all right and there we go sure enough that process is running now let's go ahead and run jobs again and we see that we have that running but we

don't get that process ID to get that we need to run and pass in the flag of L and that gives us our process ID so when you want to kill this process just like that you

type in kill and then you need to give it the process ID in our case 2900 8 and that ends the process notice it says done and at that point it is done with that process

if we run jobs again that's empty there's nothing there and of course if we were to give it a new job it doesn't work all right now at this stage we've lost the ability

to see what things have processed and what kind of errors we are getting so to add to that what we could do is called the same command again so that is PHP artisan cue work but

before the ampersand we could put a greater than sign which basically pipes whatever comes out of that command into another place and the place that we're going to put it at is storage logs

there's a directory specifically for logs that comes in with lerigot and let's just call it jobs log run that again alright so we have that running in the background let's

give it a new job a new customer one more time and that's running and now let's switch back to PHP storm and if we go into storage logs we have this new jobs dot log and if we open that file we

see that same exact output that we were getting in the terminal but now we're getting it in a file and of course we are running if we go back over here we do have our new email that popped in so

now we have a place a log for all of our files to go into and that's pretty cool now one thing about this is that if that process was to fail nothing really happens I mean the jobs stopped running

and everything gets backed up so you need something else right you need supervisor supervisor is another piece of software that is beyond the scope of this course but you could do some Google

searches and find some stuff on how to set up supervisor and what supervisor will do is if this process stops running for any reason it will restart it for you and get

again that way your jobs don't get backed up so that's more like what you would do in a production situation however for development this is perfectly fine because you can always

run these jobs with the flag of L and you know if your process is still running if that process fails you can simply boot it back up by yourself so let me go ahead and kill that process

again so that's twenty nine seven fifty and now we're no longer processing jobs so with that now you know how to be able to run that queue work in the background that way you could get your terminal

prompt back up now typically in development like we talked about you wouldn't really do this you'd kind of just leave a tab there open for you you don't really need to run this in the

background but you can there's really no reason to do one over the other they're both basically the same in your development environment so that wraps it up for this lesson if you didn't catch

the previous episode episode 29 catch that one that is all about how we set up our queues and how we refactor our code two queued a ten-second long process that way the user doesn't have to wait

so that interest you go ahead and check out episode 29

Now that we have our jobs running, let’s explore how we can run the queue:work command in the background. As it turns out, it’s actually quite simple to do. Follow along as we set it up from scratch.

For the best experience, follow along in our interactive school at

Course Source Code

Hit us up on Twitter with any questions or comments @codertape (

About This Course

Ready to get started on your path to Laravel Artisan? In this series, we are breaking down all of the basics of Laravel to get you comfortable using the world’s most popular PHP framework. Let’s get started!

    add to database laravel admin laravel artisan Artisan Command artisan commend create artisan console artisan laravel command authentication in laravel belongsto belongsto laravel example coding tutorials create artisan command create command artisan create new command artisan Create your own crud laravel crud laravel tutorial crud resource laravel crud with file upload custom artisan commands custom artisan commands laravel custom laravel database configuration laravel database relationship digital ocean dotenv eager loading eager loading in laravel eager loading vs lazy loading laravel eloquent eloquent accessors eloquent mutators eloquent orm feature testing laravel fetching data in laravel filesystem laravel form requests full stack vue gate and policy laravel google optimize hasmany hasmany laravel hasmany laravel example hasmany relationship in laravel hasone hasone relationship in laravel How to create how to queue email how to use queue installing laravel intervention image laravel laravel 5 laravel 5 auth laravel 5.4 queue laravel 5.5 queue laravel 5.8 laravel 5.8 artisan command laravel 5.8 artisan console laravel 5.8 auth tutorial laravel 5.8 authentication laravel 5.8 commands laravel 5.8 crud laravel 5.8 crud example laravel 5.8 custom middleware laravel 5.8 deprecations laravel 5.8 eager loading laravel 5.8 elixir laravel 5.8 event listeners laravel 5.8 events laravel 5.8 feature laravel 5.8 features laravel 5.8 global middleware laravel 5.8 install laravel 5.8 lazy loading laravel 5.8 listeners laravel 5.8 middleware laravel 5.8 multi auth laravel 5.8 named resource routes laravel 5.8 named routes laravel 5.8 new feature laravel 5.8 own artisan command laravel 5.8 queue laravel 5.8 queues laravel 5.8 routing laravel 5.8 telescope laravel 5.8 tutorial laravel 5.8 user auth laravel 5.8 user authentication laravel 5.8 what's new laravel 5.9 laravel admin permissions laravel api laravel artisan command laravel artisan console laravel assets laravel auth laravel auth role laravel authentication laravel authorization laravel axios post example laravel background process laravel background task laravel background worker laravel beginner to master laravel belongsto laravel belongsto vs hasone laravel belongstomany laravel best packages laravel best practices laravel best tutorial laravel bootstrap laravel command laravel command line laravel commands tutorial laravel composer install laravel connect db laravel console command laravel console testing laravel contact form send email laravel controllers laravel create laravel crud laravel crud policy laravel custom command laravel custom middleware laravel database laravel database configuration laravel database relationships laravel database seeder laravel database settings laravel db seed laravel db settings laravel debugging laravel deploy aws laravel deploy digital ocean laravel deploy on digitalocean laravel deploy on server laravel deploy to production laravel deployment laravel digitalocean laravel drag and drop file upload laravel dropzone file upload laravel dropzone image upload laravel e-commerce laravel eager loading laravel eager loading tutorial laravel eager loading with condition laravel elixir laravel eloquent laravel eloquent belongsto laravel eloquent crud laravel eloquent hasmany laravel eloquent where laravel eloquest tutorial laravel events and queue laravel events tutorial laravel factory laravel feature test laravel feature testing laravel fetching data from database laravel file storage laravel fillable example laravel flash message notification laravel for beginners laravel form validation laravel forms laravel forms bootstrap snippets laravel from scratch laravel from the ground up laravel front end laravel frontend tutorial laravel gate and policy tutorial laravel global middleware laravel hasmany laravel hasone laravel i18n laravel installation laravel installation mac laravel intervention image tutorial laravel javascript tutorial laravel jobs queue laravel language laravel language switcher laravel language tutorial laravel languages laravel lazy loading laravel listener event laravel listeners laravel localization laravel login laravel mailable tutorial laravel many to many relationship example laravel markdown email laravel markdown mail laravel mass assignment laravel middleware laravel migrate fresh laravel mix laravel mix 5.8 laravel mix vue laravel model factory tutorial laravel multiple language laravel mysql json laravel named resource routes laravel named routes laravel new features laravel news laravel nginx laravel node modules laravel npm install laravel npm run watch error laravel one to one laravel paginate laravel paginate link laravel pagination laravel pagination 5.8 laravel pagination links laravel pagination tutorial laravel phpunit laravel phpunit testing laravel pivot table example laravel policy laravel preview laravel query optimization laravel queue laravel queue event listener laravel react laravel register user laravel registration laravel registration validation laravel relationships laravel reset password laravel role middleware laravel role permission laravel roles laravel route group middleware laravel routes laravel routing laravel routing with parameters laravel sass laravel save file to database laravel scopes laravel seo tutorial laravel server laravel session data laravel ssl laravel supervisor laravel tailwind css laravel tailwind setup laravel tdd laravel tdd tutorial laravel telescope laravel telescope installation laravel telescope tutorial laravel test driven development laravel test workflow laravel testing laravel testing controllers laravel testing tutorial laravel tools laravel translation laravel tutorial laravel tutorial for beginners laravel ubuntu server laravel ubuntu tutorial laravel unit testing controllers laravel upload file laravel upload image to storage laravel upload multiple files at once laravel upload multiple image to database laravel upload multiple images laravel url slug laravel vue laravel vue js crud laravel vue setup laravel vue tutorial laravel vue.js laravel webpack error laravel webpack tutorial lazy loading lazy loading laravel lazy loading vs eager loading learn laravel learn laravel framework step by step localization in laravel localization laravel many to many laravel mvc tutorial for beginners in php mvc tutorial laravel mysql mysql relational database mysql relationship n + 1 problem n + 1 problem laravel new artisan command npm install npm run dev npm run watch laravel one to many one to one one to one laravel own artisan command pagination pagination bootstrap pagination bootstrap php mysql pagination laravel pagination laravel bootstrap pagination links pagination php php php artisan php carbon immutable php framework php framework 2019 php what's new 2019 phpunit phpunit laravel phpunit testing pivot laravel policy laravel polymorphic relationships queue and events queue email queue for laravel queue jobs queue laravel 5.8 registration form relationship laravel eloquent relationship mysql restful controller role permission in laravel roles laravel route model binding laravel routing in laravel save image to database seo friendly seo friendly content writing seo friendly website seo laravel seo optimization simple pagination laravel slugify sqlite relational database sqlite relationships between tables symfony command console symfony laravel tailwind css tailwind laravel mix telescope laravel tutorial laravel unit testing unit testing laravel upload file laravel upload file php upload image laravel upload image to database php upload images laravel upload multiple files in php url slug laravel url slug php vue vue.js vuejs laravel why use laravel queue why use queue