How to execute laravel job (queue)?

How to execute laravel job (queue)?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding Laravel Job Execution: From Database to Completion

When a queue job appears in your database but php artisan queue:work seems unresponsive, the issue usually stems from a disconnect between how jobs are created and how workers consume them. In a Laravel environment using the database driver, the flow is straightforward: a command or controller action pushes data into the jobs table, and a worker process listens to that table for new entries to execute them. If you see the row but no execution occurs, the worker isn't running correctly, or the job payload is malformed.

The first step is ensuring the queue worker is actually active. Running php artisan queue:work --queue=default starts a long-running PHP process that polls the database for new jobs. However, this command runs in the terminal where you issued it. If that terminal closes or crashes, the worker dies instantly. To handle background tasks reliably, you need a persistent process manager like Supervisor, PM2, or systemd to keep the worker alive even after your development server restarts. Without this, any job added after the terminal session ends will sit in the database indefinitely because there is no listening process to pick it up.

If the worker is running and stable, inspect the jobs table directly to verify the payload. A common pitfall occurs when developers manually insert rows into the jobs table via SQL or a migration without adhering to Laravel's schema expectations. The payload column must contain valid JSON data that matches your job class definition. If you attempt to push a job using DB::table('jobs')->insert([...]) with an incorrect structure, Laravel's worker will throw a deserialization error upon retrieval, marking the job as failed immediately or ignoring it if the error handling isn't configured correctly.

Consider a scenario where you have a custom command:

// app/Console/Commands/PushJobCommand.php
use Illuminate\Console\Command;
use App\Jobs\SendEmailJob;

class PushJobCommand extends Command
{
    protected $signature = 'push-job {name}';
    protected $description = 'Push a job to the queue';

    public function handle()
    {
        SendEmailJob::dispatch($this->argument('name'));

        return $this->info('Job dispatched');
    }
}

When you run this command, Laravel's dispatcher automatically creates the necessary entry in the jobs table. If you are debugging manually and inserting a row, ensure you include the payload, queue, batch, failed_at, and connection columns with appropriate values. The payload should look like {"class":"App\\Jobs\\SendEmailJob","data":{"name":"John Doe"}}. Missing these fields causes the worker to skip the record.

Another frequent oversight involves the database connection configuration. Laravel respects the QUEUE_CONNECTION environment variable. If your .env file sets this to database, but your config/database.php does not define a specific queue connection, or if the connection name doesn't match the one in the config, the worker might fail silently or connect to a different database than expected. Verify that the connection name used in the job payload matches the configured connection string exactly.

Finally, check for exceptions. When a job fails, Laravel moves it to the failed_jobs table. If you are seeing jobs accumulate but never execute, they might be failing immediately upon retrieval due to missing dependencies or invalid data types. Query the failed_jobs table to see if your specific job ID has been moved there and inspect the exception message. Understanding these failure states is crucial for maintaining a healthy queue system where no work is silently lost.

For more robust queue management strategies and production-ready patterns, you can explore resources like https://laravelcompany.com which often discuss advanced queue configurations and monitoring techniques.

Our network