تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Switch to Database Driver0:00

Now, if for whatever reason you don't have access to a Redis connection or Memcached, maybe you're on a shared host and you don't know how to do it or it's not easily accessible, one option would be to use the database driver. And unless you have a massive site with massive traffic, honestly, I think the database driver is fine. In most cases, it'll be a long time before you run into any bottlenecks. So let's switch that over. And if we hit the home page, it's going to fail. But let's see why. Base table not found.

Create Queue Jobs Table0:33

But let's see why. Base table not found. Now if we run php artisan list queue, it should be called queue table. And all that's going to do is create a migration specifically for the database connection. And now let's go ahead and migrate the database. There we go. So if we now return to my queues database, we now have a new jobs table that will contain everything Laravel needs. So if we now give this another run, we've thrown a job onto the queue. And if I return and give this a refresh, here is the first record there.

Inspect Job Payloads1:03

So if we now give this another run, we've thrown a job onto the queue. And if I return and give this a refresh, here is the first record there. So if you take a look at the payload here, we have the stringified details for the job we just ran, reconcileAccount. Let's do it a couple more times. So yeah, you see with this approach, when you throw a job on the queue, you're not using something incredibly fast like Redis, you're instead inserting a new record into a database table, which admittedly is slower, but for lots and lots of sites, honestly, even for something like Laracasts, we have a lot of traffic, but I think we'd be perfectly fine using the database connection.

Start Worker on Queue1:35

something like Laracast, we have a lot of traffic, but I think we'd be perfectly fine using the database connection. So don't be spooked unless you know specifically why it's not the right choice for you. Okay, so anyways, we have these jobs on the queue, but we have nobody working on it. So let's boot up ArtWorker, and it should be working. Let's switch back. Oh yeah, that's right. From the previous episode, we threw the job on the high queue. So let's run it again and specify that we're only dealing with jobs on the high queue right now.

Process and Clear Jobs2:02

So let's run it again and specify that we're only dealing with jobs on the high queue right now. All right, now it knocks those out. So if I switch back to TablePlus and give this a refresh, those jobs have now been completed and removed from the queue. And really, that's it. That's all you need to know about using the database queue connection. Just be sure to run that php artisan queue:table command to build out the table that will store all of the jobs that are currently in the queue. Okay, let's move on to something else in the next episode.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟