PHPackages                             wp-media/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. wp-media/background-processing

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

wp-media/background-processing
==============================

Async &amp; Background Tasks Processing

v1.3.2(5y ago)4192.2k↓42.3%22GPL-2.0+PHPCI failing

Since Feb 21Pushed 4y ago13 watchersCompare

[ Source](https://github.com/wp-media/background-processing)[ Packagist](https://packagist.org/packages/wp-media/background-processing)[ Docs](https://github.com/wp-media/background-processing)[ RSS](/packages/wp-media-background-processing/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (5)Used By (2)

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.

Inspired by [TechCrunch WP Asynchronous Tasks](https://github.com/techcrunch/wp-async-task) and [DeliciousBrains](https://deliciousbrains.com/background-processing-wordpress/).

**Requires PHP 5.2+**

### 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();`

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

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~218 days

Total

3

Last Release

1842d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5564218f7cd2ccf4542a09b7c5436e61e6b370c97fb3b04db1c5bbc0cc67e3c1?d=identicon)[wpmedia](/maintainers/wpmedia)

---

Top Contributors

[![remyperona](https://avatars.githubusercontent.com/u/3465180?v=4)](https://github.com/remyperona "remyperona (6 commits)")[![engahmeds3ed](https://avatars.githubusercontent.com/u/15707971?v=4)](https://github.com/engahmeds3ed "engahmeds3ed (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wp-media-background-processing/health.svg)

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

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[enqueue/enqueue

Message Queue Library

19820.0M56](/packages/enqueue-enqueue)[deliciousbrains/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.

1.1k409.8k6](/packages/deliciousbrains-wp-background-processing)[react/async

Async utilities and fibers for ReactPHP

2228.8M171](/packages/react-async)[react/promise-stream

The missing link between Promise-land and Stream-land for ReactPHP

11512.9M45](/packages/react-promise-stream)[illuminate/bus

The Illuminate Bus package.

6043.8M409](/packages/illuminate-bus)

PHPackages © 2026

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