<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Queue on Daniel Zhang</title><link>https://zhangdapeng.dev/tags/queue/</link><description>Recent content in Queue on Daniel Zhang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 18 Nov 2026 14:30:00 +0800</lastBuildDate><atom:link href="https://zhangdapeng.dev/tags/queue/index.xml" rel="self" type="application/rss+xml"/><item><title>Laravel 5.2 Queue Commands Explained: A Practical Guide to Queue Management</title><link>https://zhangdapeng.dev/p/laravel-5-2-queue-commands-guide/</link><pubDate>Wed, 18 Nov 2026 14:30:00 +0800</pubDate><guid>https://zhangdapeng.dev/p/laravel-5-2-queue-commands-guide/</guid><description>&lt;img src="https://zhangdapeng.dev/p/laravel-5-2-queue-commands-guide/cover.png" alt="Featured image of post Laravel 5.2 Queue Commands Explained: A Practical Guide to Queue Management" /&gt;&lt;h1 id="laravel-52-queue-commands-explained-a-practical-guide-to-queue-management"&gt;Laravel 5.2 Queue Commands Explained: A Practical Guide to Queue Management
&lt;/h1&gt;&lt;p&gt;Laravel provides a built-in queue system that allows applications to process time-consuming tasks asynchronously. Common use cases include sending emails, processing uploaded files, generating reports, and handling background operations.&lt;/p&gt;
&lt;p&gt;Laravel 5.2 provides several Artisan commands for managing queues, including starting workers, restarting background processes, and handling failed jobs.&lt;/p&gt;
&lt;p&gt;This article explains the most commonly used Laravel 5.2 queue commands, their purposes, and when to use each one in a real production environment.&lt;/p&gt;
&lt;h2 id="1-understanding-laravel-queue-architecture"&gt;1. Understanding Laravel Queue Architecture
&lt;/h2&gt;&lt;p&gt;Before looking at individual commands, it is important to understand how Laravel queues work.&lt;/p&gt;
&lt;p&gt;A typical queue workflow looks like this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The application dispatches a job.&lt;/li&gt;
&lt;li&gt;Laravel pushes the job into a queue backend, such as a database or Redis.&lt;/li&gt;
&lt;li&gt;A queue worker retrieves the job.&lt;/li&gt;
&lt;li&gt;The worker executes the job.&lt;/li&gt;
&lt;li&gt;If execution fails, Laravel can record the failure in the &lt;code&gt;failed_jobs&lt;/code&gt; table.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There are three important components:&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Component&lt;/th&gt;
					&lt;th&gt;Responsibility&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Queue Driver&lt;/td&gt;
					&lt;td&gt;Stores pending jobs&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Queue Worker&lt;/td&gt;
					&lt;td&gt;Retrieves and executes jobs&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Failed Jobs Storage&lt;/td&gt;
					&lt;td&gt;Records jobs that fail during execution&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Laravel 5.2 supports several queue drivers, including &lt;code&gt;sync&lt;/code&gt;, &lt;code&gt;database&lt;/code&gt;, &lt;code&gt;beanstalkd&lt;/code&gt;, and Redis.&lt;/p&gt;
&lt;p&gt;For production environments, database or Redis is generally more suitable than the synchronous driver.&lt;/p&gt;
&lt;h2 id="2-queue-initialization-commands"&gt;2. Queue Initialization Commands
&lt;/h2&gt;&lt;p&gt;These commands are primarily used when setting up the queue system for the first time.&lt;/p&gt;
&lt;h3 id="21-queuetable"&gt;2.1 &lt;code&gt;queue:table&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Generate a migration file for the &lt;code&gt;jobs&lt;/code&gt; table.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:table
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The generated migration creates the database table used by Laravel&amp;rsquo;s database queue driver.&lt;/p&gt;
&lt;p&gt;Run the migration afterward:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan migrate
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When configuring the database queue driver for the first time.&lt;/li&gt;
&lt;li&gt;When the &lt;code&gt;jobs&lt;/code&gt; table does not exist.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You do not need this command if you are using Redis as your queue backend.&lt;/p&gt;
&lt;h3 id="22-queuefailed-table"&gt;2.2 &lt;code&gt;queue:failed-table&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Generate a migration file for the &lt;code&gt;failed_jobs&lt;/code&gt; table.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:failed-table
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then execute:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan migrate
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This table stores information about failed jobs, including their connection, queue name, payload, exception details, and failure timestamp.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When enabling failed job tracking.&lt;/li&gt;
&lt;li&gt;When setting up a new production queue environment.&lt;/li&gt;
&lt;li&gt;When you need to investigate and retry failed jobs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It is recommended to configure failed job storage even when using Redis or another queue backend.&lt;/p&gt;
&lt;h2 id="3-queue-worker-commands"&gt;3. Queue Worker Commands
&lt;/h2&gt;&lt;p&gt;These are the commands you will use most frequently when running Laravel queues.&lt;/p&gt;
&lt;h3 id="31-queuework"&gt;3.1 &lt;code&gt;queue:work&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Start a queue worker.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In Laravel 5.2, &lt;code&gt;queue:work&lt;/code&gt; can run in different modes.&lt;/p&gt;
&lt;p&gt;For a continuously running daemon worker:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work --daemon
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;--daemon&lt;/code&gt; option keeps the worker process alive and allows it to process multiple jobs without bootstrapping the entire Laravel application for every job.&lt;/p&gt;
&lt;p&gt;This significantly reduces overhead and improves processing efficiency.&lt;/p&gt;
&lt;p&gt;A typical production command is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work --daemon --tries&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also specify additional options:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work --daemon &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --sleep&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --tries&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; --timeout&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;60&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Option&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;--daemon&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Run the worker as a long-lived process&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;--sleep=3&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Wait 3 seconds when no jobs are available&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;--tries=3&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Maximum number of attempts before failure&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;--timeout=60&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Maximum execution time for a job, in seconds&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Production queue processing.&lt;/li&gt;
&lt;li&gt;Running background jobs continuously.&lt;/li&gt;
&lt;li&gt;Deploying queue workers under Supervisor.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Because daemon workers keep the Laravel application in memory, they do not automatically load newly deployed application code. A graceful restart is required after deployment.&lt;/p&gt;
&lt;h3 id="32-queuelisten"&gt;3.2 &lt;code&gt;queue:listen&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Start a queue listener:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:listen
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Unlike a daemon worker, &lt;code&gt;queue:listen&lt;/code&gt; starts a fresh application process for each job.&lt;/p&gt;
&lt;p&gt;This means application code changes can be picked up automatically by subsequent jobs without manually restarting a long-running worker.&lt;/p&gt;
&lt;p&gt;However, this approach introduces additional application bootstrapping overhead.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Local development.&lt;/li&gt;
&lt;li&gt;Debugging queue jobs.&lt;/li&gt;
&lt;li&gt;Environments where automatically loading updated code is more important than worker performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For production environments with high queue throughput, &lt;code&gt;queue:work --daemon&lt;/code&gt; is generally more efficient.&lt;/p&gt;
&lt;h3 id="33-queuerestart"&gt;3.3 &lt;code&gt;queue:restart&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Gracefully restart running queue workers.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:restart
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is one of the most important commands when deploying Laravel applications.&lt;/p&gt;
&lt;p&gt;In Laravel 5.2, daemon workers load application code when they start. If you deploy new code while workers are running, existing workers may continue using the old code.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;queue:restart&lt;/code&gt; command solves this problem.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Laravel writes a restart timestamp to the configured cache.&lt;/li&gt;
&lt;li&gt;Running workers periodically check this timestamp.&lt;/li&gt;
&lt;li&gt;When a worker detects a restart request, it finishes its current job.&lt;/li&gt;
&lt;li&gt;The worker exits gracefully.&lt;/li&gt;
&lt;li&gt;Supervisor starts a replacement worker if it manages the process.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Importantly, &lt;code&gt;queue:restart&lt;/code&gt; does not immediately terminate a worker that is processing a job.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;After deploying new application code.&lt;/li&gt;
&lt;li&gt;After modifying existing Job classes.&lt;/li&gt;
&lt;li&gt;After modifying code used by queue workers.&lt;/li&gt;
&lt;li&gt;When you want to reload workers without interrupting their current jobs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For production deployments, this command should generally be included in your deployment process.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Deploy application code&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Refresh Composer autoload files if necessary&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;composer dump-autoload -o
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Gracefully restart Laravel queue workers&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:restart
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; &lt;code&gt;queue:restart&lt;/code&gt; only requests workers to exit. It does not start new workers by itself. A process manager such as Supervisor should be responsible for bringing them back online.&lt;/p&gt;
&lt;p&gt;Also ensure that the application cache used by the restart mechanism is shared with the running workers.&lt;/p&gt;
&lt;h2 id="4-failed-job-management-commands"&gt;4. Failed Job Management Commands
&lt;/h2&gt;&lt;p&gt;Jobs can fail for various reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Database connection problems.&lt;/li&gt;
&lt;li&gt;Third-party API timeouts.&lt;/li&gt;
&lt;li&gt;Invalid application data.&lt;/li&gt;
&lt;li&gt;Unhandled exceptions.&lt;/li&gt;
&lt;li&gt;External service outages.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Laravel provides several commands to investigate and manage failed jobs.&lt;/p&gt;
&lt;h3 id="41-queuefailed"&gt;4.1 &lt;code&gt;queue:failed&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;List all failed jobs.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:failed
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The output typically includes:&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Field&lt;/th&gt;
					&lt;th&gt;Description&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;ID&lt;/td&gt;
					&lt;td&gt;Failed job identifier&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Connection&lt;/td&gt;
					&lt;td&gt;Queue connection&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Queue&lt;/td&gt;
					&lt;td&gt;Queue name&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Class&lt;/td&gt;
					&lt;td&gt;Job class&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Failed At&lt;/td&gt;
					&lt;td&gt;Failure timestamp&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When background tasks are not completing successfully.&lt;/li&gt;
&lt;li&gt;When investigating production errors.&lt;/li&gt;
&lt;li&gt;When identifying jobs that need to be retried.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-queueretry"&gt;4.2 &lt;code&gt;queue:retry&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Retry a failed job.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:retry &lt;span class="m"&gt;5&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here, &lt;code&gt;5&lt;/code&gt; represents the failed job ID.&lt;/p&gt;
&lt;p&gt;To retry all failed jobs:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:retry all
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Laravel moves the selected failed jobs back into the queue for processing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;After fixing a bug that caused job failures.&lt;/li&gt;
&lt;li&gt;After restoring an unavailable third-party service.&lt;/li&gt;
&lt;li&gt;When retrying jobs that failed because of temporary infrastructure problems.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before retrying, make sure the underlying problem has been resolved.&lt;/p&gt;
&lt;p&gt;Also consider whether the job is safe to execute more than once. Operations such as payments and order creation should use appropriate idempotency protection.&lt;/p&gt;
&lt;h3 id="43-queueforget"&gt;4.3 &lt;code&gt;queue:forget&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Delete a specific failed job record.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:forget &lt;span class="m"&gt;5&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This removes the failed job with ID &lt;code&gt;5&lt;/code&gt; from the &lt;code&gt;failed_jobs&lt;/code&gt; table.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When a failed job is no longer relevant.&lt;/li&gt;
&lt;li&gt;When a job contains invalid or outdated data.&lt;/li&gt;
&lt;li&gt;When you have investigated the failure and decided not to retry it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Be careful: deleting the record removes the stored failure information.&lt;/p&gt;
&lt;h3 id="44-queueflush"&gt;4.4 &lt;code&gt;queue:flush&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Delete all failed job records.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:flush
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This clears the failed job storage.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to use it:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When old failed jobs are no longer needed.&lt;/li&gt;
&lt;li&gt;During maintenance after reviewing historical failures.&lt;/li&gt;
&lt;li&gt;When cleaning up accumulated failed job records.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; This operation is destructive. Once the records are deleted, you cannot use &lt;code&gt;queue:retry&lt;/code&gt; to retry those jobs.&lt;/p&gt;
&lt;p&gt;Always review failed jobs before running this command in production.&lt;/p&gt;
&lt;h2 id="5-recommended-production-workflow"&gt;5. Recommended Production Workflow
&lt;/h2&gt;&lt;p&gt;For a Laravel 5.2 production application, a typical queue management setup looks like this:&lt;/p&gt;
&lt;h3 id="step-1-configure-the-queue-driver"&gt;Step 1: Configure the Queue Driver
&lt;/h3&gt;&lt;p&gt;Set the queue driver in &lt;code&gt;.env&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-env" data-lang="env"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;QUEUE_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;database
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For Redis:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-env" data-lang="env"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;QUEUE_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;redis
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The appropriate queue backend must also be configured in &lt;code&gt;config/queue.php&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="step-2-initialize-queue-tables"&gt;Step 2: Initialize Queue Tables
&lt;/h3&gt;&lt;p&gt;If using the database driver:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:table
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:failed-table
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan migrate
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="step-3-start-queue-workers"&gt;Step 3: Start Queue Workers
&lt;/h3&gt;&lt;p&gt;Use a daemon worker:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work --daemon --tries&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For production, use Supervisor to manage the worker process.&lt;/p&gt;
&lt;h3 id="step-4-deploy-new-code"&gt;Step 4: Deploy New Code
&lt;/h3&gt;&lt;p&gt;After deploying new application code:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;composer dump-autoload -o
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:restart
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Supervisor will restart workers that exit after finishing their current jobs.&lt;/p&gt;
&lt;h3 id="step-5-monitor-failed-jobs"&gt;Step 5: Monitor Failed Jobs
&lt;/h3&gt;&lt;p&gt;Periodically check:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:failed
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Retry jobs after resolving their underlying problems:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:retry all
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Only retry jobs when doing so is safe.&lt;/p&gt;
&lt;h2 id="6-common-queue-commands-cheat-sheet"&gt;6. Common Queue Commands Cheat Sheet
&lt;/h2&gt;&lt;p&gt;Here is a quick reference for the commands covered in this article.&lt;/p&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Command&lt;/th&gt;
					&lt;th&gt;Purpose&lt;/th&gt;
					&lt;th&gt;Typical Usage&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:table&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Generate jobs table migration&lt;/td&gt;
					&lt;td&gt;Initial setup&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:failed-table&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Generate failed jobs migration&lt;/td&gt;
					&lt;td&gt;Initial setup&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:work&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Start a queue worker&lt;/td&gt;
					&lt;td&gt;Queue processing&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:listen&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Listen for and process jobs&lt;/td&gt;
					&lt;td&gt;Development&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:restart&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Gracefully restart workers&lt;/td&gt;
					&lt;td&gt;After deployment&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:failed&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;List failed jobs&lt;/td&gt;
					&lt;td&gt;Troubleshooting&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:retry&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Retry failed jobs&lt;/td&gt;
					&lt;td&gt;Recovery&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:forget&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Delete one failed job&lt;/td&gt;
					&lt;td&gt;Cleanup&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;queue:flush&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Delete all failed jobs&lt;/td&gt;
					&lt;td&gt;Maintenance&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="7-important-notes-for-laravel-52"&gt;7. Important Notes for Laravel 5.2
&lt;/h2&gt;&lt;p&gt;When managing queues in Laravel 5.2, keep the following points in mind:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Daemon workers need to be restarted after deployment.&lt;/strong&gt; They do not automatically reload modified PHP classes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Supervisor in production.&lt;/strong&gt; It ensures that queue workers are automatically restarted when they exit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use &lt;code&gt;queue:restart&lt;/code&gt; for graceful restarts.&lt;/strong&gt; It allows workers to finish their current jobs before exiting.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Monitor failed jobs regularly.&lt;/strong&gt; Do not blindly retry all failed jobs without understanding why they failed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configure appropriate timeouts and retry limits.&lt;/strong&gt; Make sure job execution time, worker timeout, and queue visibility or retry timing are configured consistently.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="conclusion"&gt;Conclusion
&lt;/h2&gt;&lt;p&gt;Laravel 5.2 provides a complete set of Artisan commands for managing the queue lifecycle, from initial database setup to worker execution and failed job recovery.&lt;/p&gt;
&lt;p&gt;For everyday production operations, the most important commands are:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Start a queue worker&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:work --daemon --tries&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Gracefully restart workers after deployment&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:restart
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Check failed jobs&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:failed
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Retry a failed job&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;php artisan queue:retry &lt;span class="m"&gt;5&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Understanding these commands helps you maintain stable background processing, deploy application updates safely, and troubleshoot queue-related issues without unnecessarily interrupting running tasks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The key takeaway:&lt;/strong&gt; Use &lt;code&gt;queue:work --daemon&lt;/code&gt; with Supervisor for production processing, and use &lt;code&gt;queue:restart&lt;/code&gt; whenever you deploy updated application code.&lt;/p&gt;</description></item></channel></rss>