PHPackages                             sebkay/wp-queued-jobs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. sebkay/wp-queued-jobs

ActiveLibrary[Queues &amp; Workers](/categories/queues)

sebkay/wp-queued-jobs
=====================

A Laravel-like queue system for WordPress.

1.0.1(3y ago)39206↓50%4[2 issues](https://github.com/SebKay/wp-queued-jobs/issues)MITPHPPHP &gt;=7.4|&gt;=8.0CI passing

Since May 27Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/SebKay/wp-queued-jobs)[ Packagist](https://packagist.org/packages/sebkay/wp-queued-jobs)[ RSS](/packages/sebkay-wp-queued-jobs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (4)Used By (0)

WP Queued Jobs
==============

[](#wp-queued-jobs)

[![Validate PHP](https://github.com/SebKay/wp-queued-jobs/actions/workflows/validate-php.yml/badge.svg)](https://github.com/SebKay/wp-queued-jobs/actions/workflows/validate-php.yml)

A [Laravel](https://laravel.com/)-like queue system for [WordPress](https://wordpress.org/).

Easily create background jobs for things like sending emails or importing large amounts of data. All with a fluent API.

I highly recommend using a plugin like [WP Crontrol](https://wordpress.org/plugins/wp-crontrol/) so you can easily see, and manually run, cron jobs from the WordPress dashboard.

**Requires PHP 7.4+**

---

Install
-------

[](#install)

The recommended way to install this package is via [Composer](https://getcomposer.org/).

```
composer require sebkay/wp-queued-jobs
```

Usage
-----

[](#usage)

### 1. Create job

[](#1-create-job)

To create a job, you need to extend the `WpQueuedJobs\Jobs\Job` class:

```
use WpQueuedJobs\Jobs\Job;

class BackgroundJob extends Job
{
    public function handle()
    {
        // Handle the job
        // Use $this->data to access what was passed with the job when it was added to the queue
    }
}
```

### 2. Add job to queue and dispatch

[](#2-add-job-to-queue-and-dispatch)

```
wpj()
    ->addJob(BackgroundJob::class, 'Data for the background job.')
    ->dispatch();
```

Anything passed as the second parameter to `addJob()` will be available in the `handle()` method of the job (and the rest of the class) as `$this->data`.

The data can be anything you want. A `string`, `array`, `integer`, `class` etc...

The "queue worker" will look for new jobs every 1 minute and run them (if there are any).

The system runs on a "first-in first-out" basis. So whatever gets dispatched first will be run first.

#### Important

[](#important)

As the lowest cron time in WordPress defaults to 1 minute, jobs scheduled to run at 6am might not actually run until 6:01am. This isn't an issue in the majority of cases, but it's worth knowing.

The point of background jobs is that they run in the background, not immediately, so they should never be used for time-sensitive tasks.

Example #1 (Send Email)
-----------------------

[](#example-1-send-email)

1. Load the "successful registration" page template.
2. Add the "send welcome email" job and dispatch it to the queue.

```
add_action('template_redirect', function () {
    if (!is_page_template('register-success.php')) {
        return;
    }

    wpj()
        ->addJob(SendWelcomeEmailJob::class, wp_get_current_user())
        ->dispatch();
}, 10, 0);
```

Example #2 (Import Posts from API)
----------------------------------

[](#example-2-import-posts-from-api)

1. Create a custom cron event.
2. Add two jobs and dispatch them to the queue.
3. Each job is given an `offset` and a `max` so the same posts aren't imported twice.
4. Schedule the cron even to run once per day at 6am, starting tomorrow.

```
add_action('import_api_posts', function () {
    wpj()
        ->addJob(ImportApiPostsJob::class, ['offset' => 0, 'max' => 100])
        ->addJob(ImportApiPostsJob::class, ['offset' => 100, 'max' => 100])
        ->dispatch();
}, 10, 0);

if (!\wp_next_scheduled('import_api_posts')) {
    \wp_schedule_event(
        \strtotime("+ 1 days 6am"),
        'daily',
        'import_api_posts'
    );
}
```

Why
---

[](#why)

Unfortunatetly there's no concept of a "queue worker" in WordPress. At it's core WordPress is just a bunch of PHP files. There's no command line runner, such as [Artisan](https://laravel.com/docs/9.x/artisan) in Laravel.

Although the [WordPress CLI](https://wp-cli.org/) exists, a lot of people host their sites on shared hosting, so that isn't an option.

This package tries to circumvent that by utilising the WordPress Cron system. It runs a WP Cron task every minute to see if there are new jobs to run. If there are then it locks the connection to the database, runs the jobs, then unlocks the connection.

It's important to lock the queue to prevent the same jobs from running multiple times. The "queue worker" checks if there are new jobs every minute, so if any queue takes longer than a minute to finish jobs won't overlap.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance57

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~236 days

Total

2

Last Release

1210d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0eb0c125a95bbb96a00c31b474c67d7761c87964bd9ba973bd3e4b896097bdb5?d=identicon)[SebKay](/maintainers/SebKay)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (22 commits)")[![SebKay](https://avatars.githubusercontent.com/u/1873695?v=4)](https://github.com/SebKay "SebKay (13 commits)")[![sabbirahmed395](https://avatars.githubusercontent.com/u/6681080?v=4)](https://github.com/sabbirahmed395 "sabbirahmed395 (1 commits)")

---

Tags

background-jobsqueuequeueswordpresswordpress-apiwordpress-background-jobswordpress-php-librarywordpress-queuewp

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sebkay-wp-queued-jobs/health.svg)

```
[![Health](https://phpackages.com/badges/sebkay-wp-queued-jobs/health.svg)](https://phpackages.com/packages/sebkay-wp-queued-jobs)
```

###  Alternatives

[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

53541.0k3](/packages/jolicode-castor)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[amphp/cluster

Building multi-core network applications with PHP.

6224.8k1](/packages/amphp-cluster)[haozu/delay-queue

Delay queue based on redis

123.4k](/packages/haozu-delay-queue)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
