PHPackages                             jetty-dev/background-processing - 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. jetty-dev/background-processing

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

jetty-dev/background-processing
===============================

WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.

1.1.2(4y ago)03.6kGPL-2.0-or-laterPHPPHP &gt;=7.1

Since Aug 7Pushed 4y agoCompare

[ Source](https://github.com/jetty-dev/background-processing)[ Packagist](https://packagist.org/packages/jetty-dev/background-processing)[ RSS](/packages/jetty-dev-background-processing/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (11)Used By (0)

WP Background Processing
========================

[](#wp-background-processing)

WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks. Check out the [example plugin](https://github.com/A5hleyRich/wp-background-processing-example) or read the [accompanying article](https://deliciousbrains.com/background-processing-wordpress/).

Inspired by [TechCrunch WP Asynchronous Tasks](https://github.com/techcrunch/wp-async-task).

**Requires PHP 5.2+**

Install
-------

[](#install)

The recommended way to install this library in your project is by loading it through Composer:

```
composer require deliciousbrains/wp-background-processing

```

It is highly recommended to prefix wrap the library class files using [the Mozart package](https://packagist.org/packages/coenjacobs/mozart), to prevent collisions with other projects using this same library.

Usage
-----

[](#usage)

### Async Request

[](#async-request)

Async requests are useful for pushing slow one-off tasks such as sending emails to a background process. Once the request has been dispatched it will process in the background instantly.

Extend the `WP_Async_Request` class:

```
class WP_Example_Request extends WP_Async_Request {

	/**
	 * @var string
	 */
	protected $action = 'example_request';

	/**
	 * Handle
	 *
	 * Override this method to perform any actions required
	 * during the async request.
	 */
	protected function handle() {
		// Actions to perform
	}

}
```

##### `protected $action`

[](#protected-action)

Should be set to a unique name.

##### `protected function handle()`

[](#protected-function-handle)

Should contain any logic to perform during the non-blocking request. The data passed to the request will be accessible via `$_POST`.

##### Dispatching Requests

[](#dispatching-requests)

Instantiate your request:

`$this->example_request = new WP_Example_Request();`

Add data to the request if required:

`$this->example_request->data( array( 'value1' => $value1, 'value2' => $value2 ) );`

Fire off the request:

`$this->example_request->dispatch();`

Chaining is also supported:

`$this->example_request->data( array( 'data' => $data ) )->dispatch();`

### Background Process

[](#background-process)

Background processes work in a similar fashion to async requests but they allow you to queue tasks. Items pushed onto the queue will be processed in the background once the queue has been dispatched. Queues will also scale based on available server resources, so higher end servers will process more items per batch. Once a batch has completed the next batch will start instantly.

Health checks run by default every 5 minutes to ensure the queue is running when queued items exist. If the queue has failed it will be restarted.

Queues work on a first in first out basis, which allows additional items to be pushed to the queue even if it’s already processing.

Extend the `WP_Background_Process` class:

```
class WP_Example_Process extends WP_Background_Process {

	/**
	 * @var string
	 */
	protected $action = 'example_process';

	/**
	 * Task
	 *
	 * Override this method to perform any actions required on each
	 * queue item. Return the modified item for further processing
	 * in the next pass through. Or, return false to remove the
	 * item from the queue.
	 *
	 * @param mixed $item Queue item to iterate over
	 *
	 * @return mixed
	 */
	protected function task( $item ) {
		// Actions to perform

		return false;
	}

	/**
	 * Complete
	 *
	 * Override if applicable, but ensure that the below actions are
	 * performed, or, call parent::complete().
	 */
	protected function complete() {
		parent::complete();

		// Show notice to user or perform some other arbitrary task...
	}

}
```

##### `protected $action`

[](#protected-action-1)

Should be set to a unique name.

##### `protected function task( $item )`

[](#protected-function-task-item-)

Should contain any logic to perform on the queued item. Return `false` to remove the item from the queue or return `$item` to push it back onto the queue for further processing. If the item has been modified and is pushed back onto the queue the current state will be saved before the batch is exited.

##### `protected function complete()`

[](#protected-function-complete)

Optionally contain any logic to perform once the queue has completed.

##### Dispatching Processes

[](#dispatching-processes)

Instantiate your process:

`$this->example_process = new WP_Example_Process();`

**Note:** You must instantiate your process unconditionally. All requests should do this, even if nothing is pushed to the queue.

Push items to the queue:

```
foreach ( $items as $item ) {
    $this->example_process->push_to_queue( $item );
}
```

Save and dispatch the queue:

`$this->example_process->save()->dispatch();`

### BasicAuth

[](#basicauth)

If your site is behind BasicAuth, both async requests and background processes will fail to complete. This is because WP Background Processing relies on the [WordPress HTTP API](http://codex.wordpress.org/HTTP_API), which requires you to attach your BasicAuth credentials to requests. The easiest way to do this is using the following filter:

```
function wpbp_http_request_args( $r, $url ) {
	$r['headers']['Authorization'] = 'Basic ' . base64_encode( USERNAME . ':' . PASSWORD );

	return $r;
}
add_filter( 'http_request_args', 'wpbp_http_request_args', 10, 2);
```

License
-------

[](#license)

[GPLv2+](http://www.gnu.org/licenses/gpl-2.0.html)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~257 days

Recently: every ~19 days

Total

8

Last Release

1769d ago

PHP version history (2 changes)1.0PHP &gt;=5.2

1.0.3PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1bc4ba46cbd3c27fd7cd047d33cbd4a5d640e2ec3a3d474c934c49f132b832bb?d=identicon)[jetty-dev](/maintainers/jetty-dev)

---

Top Contributors

[![EvanWashkow](https://avatars.githubusercontent.com/u/2553816?v=4)](https://github.com/EvanWashkow "EvanWashkow (45 commits)")[![A5hleyRich](https://avatars.githubusercontent.com/u/1422996?v=4)](https://github.com/A5hleyRich "A5hleyRich (33 commits)")[![polevaultweb](https://avatars.githubusercontent.com/u/1770201?v=4)](https://github.com/polevaultweb "polevaultweb (11 commits)")[![Hoho5000](https://avatars.githubusercontent.com/u/15811185?v=4)](https://github.com/Hoho5000 "Hoho5000 (5 commits)")[![mikejolley](https://avatars.githubusercontent.com/u/90977?v=4)](https://github.com/mikejolley "mikejolley (3 commits)")[![theKhorshed](https://avatars.githubusercontent.com/u/10390188?v=4)](https://github.com/theKhorshed "theKhorshed (3 commits)")[![bhubbard](https://avatars.githubusercontent.com/u/3837?v=4)](https://github.com/bhubbard "bhubbard (2 commits)")[![ianmjones](https://avatars.githubusercontent.com/u/4710?v=4)](https://github.com/ianmjones "ianmjones (2 commits)")[![coenjacobs](https://avatars.githubusercontent.com/u/245703?v=4)](https://github.com/coenjacobs "coenjacobs (2 commits)")[![AndrewKvalheim](https://avatars.githubusercontent.com/u/1844746?v=4)](https://github.com/AndrewKvalheim "AndrewKvalheim (1 commits)")[![leewillis77](https://avatars.githubusercontent.com/u/1097338?v=4)](https://github.com/leewillis77 "leewillis77 (1 commits)")[![boonebgorges](https://avatars.githubusercontent.com/u/246627?v=4)](https://github.com/boonebgorges "boonebgorges (1 commits)")[![cjeanrichard](https://avatars.githubusercontent.com/u/2415665?v=4)](https://github.com/cjeanrichard "cjeanrichard (1 commits)")[![markjaquith](https://avatars.githubusercontent.com/u/353790?v=4)](https://github.com/markjaquith "markjaquith (1 commits)")[![No3x](https://avatars.githubusercontent.com/u/2690708?v=4)](https://github.com/No3x "No3x (1 commits)")

### Embed Badge

![Health badge](/badges/jetty-dev-background-processing/health.svg)

```
[![Health](https://phpackages.com/badges/jetty-dev-background-processing/health.svg)](https://phpackages.com/packages/jetty-dev-background-processing)
```

###  Alternatives

[symfony/messenger

Helps applications send and receive messages to/from other applications or via message queues

1.1k120.7M958](/packages/symfony-messenger)[symfony/amazon-sqs-messenger

Symfony Amazon SQS extension Messenger Bridge

4612.5M15](/packages/symfony-amazon-sqs-messenger)[pmg/queue

A task queue framework for PHP

13460.6k8](/packages/pmg-queue)[webfactory/icu-translation-bundle

Enables ICU message formatting for translations in Symfony applications.

2761.8k](/packages/webfactory-icu-translation-bundle)[amphp/cluster

Building multi-core network applications with PHP.

6224.8k1](/packages/amphp-cluster)[workerman/rabbitmq

Asynchronous rabbitmq client for PHP based on workerman.

4313.4k6](/packages/workerman-rabbitmq)

PHPackages © 2026

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