Download the PHP package duckdev/wp-queue-process without Composer
On this page you can find all versions of the php package duckdev/wp-queue-process. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download duckdev/wp-queue-process
More information about duckdev/wp-queue-process
Files in duckdev/wp-queue-process
Package wp-queue-process
Short Description WordPress non-blocking async requests and background queue processing with a swappable storage driver, server-load aware batching, and a self-healing cron.
License GPL-2.0-or-later
Homepage https://github.com/foxelabs/wp-queue-process
Informations about the package wp-queue-process
WP Queue Process
WP Queue Process is a WordPress library for firing off non-blocking asynchronous requests and for running long jobs as a background queue. Items pushed onto the queue are worked through in batches that bail out before exhausting the server's time or memory budget, each finished batch chains the next instantly, and a self-healing cron restarts a stalled queue.
- Inspired by TechCrunch WP Asynchronous Tasks.
- Forked from WP Background Processing, modernised with a swappable storage driver, a server-load guard, and a full test suite.
📖 Full documentation: docs.duckdev.com/wp-libraries/wp-queue-process/overview
Requirements
- PHP 7.4 or higher
- WordPress 6.0+
- Composer
Installation
The library autoloads under the DuckDev\Queue\ namespace via PSR-4.
Architecture
Consumers extend one of two abstract classes — Async for a one-off request, Task for a queue. Everything else is a
collaborator that Task wires up for you and that you can swap or mock through the constructor. The folder layout
mirrors the namespace:
Task delegates persistence to a StoreInterface, load-guarding to ServerLimits, and single-worker locking to
ProcessLock. All three are injected through the constructor (with WordPress-backed defaults), so the batch loop can be
unit-tested without a database.
Usage
Async Request
Async requests are useful for pushing slow one-off tasks — sending an email, warming a cache — to a background process. Once dispatched, the request processes immediately and out of band.
Extend \DuckDev\Queue\Async:
Dispatch it (chaining is supported):
Background Process
Background processes queue tasks and work through them in batches. Higher-end servers process more items per batch. A health check runs by default every 5 minutes to restart the queue if it ever fails; queues are processed first-in-first-out, so items can be pushed even while one is already running.
Extend \DuckDev\Queue\Task:
Instantiate the process unconditionally (every request, even when nothing is queued), push items, then save and dispatch:
Public methods
| Method | Description |
|---|---|
push_to_queue( $item ) |
Append a single item to the in-memory queue. |
set_queue( array $items ) |
Replace the in-memory queue wholesale. |
save( string $group = 'default' ) |
Persist the in-memory queue as a new batch. |
dispatch() |
Schedule the health-check cron and start processing. |
update( string $key, array $data ) |
Replace the items of an existing batch. |
delete( string $key ) |
Delete a batch entirely. |
cancel_process() |
Drop the current batch and clear the cron. |
Swapping the storage driver
The default OptionStore keeps batches in the (network) options table. Pass your own StoreInterface — or a custom
ServerLimits / ProcessLock — to the constructor to change where batches live or how aggressively a batch runs:
Filters
Every filter is namespaced with the process identifier ({prefix}_{action}, e.g. duckdev_example_process):
| Filter | Default | Purpose |
|---|---|---|
{id}_query_args |
action + nonce | Query args added to the dispatch URL. |
{id}_query_url |
admin-ajax.php |
URL the request is dispatched to. |
{id}_post_args |
non-blocking POST | Arguments passed to wp_remote_post(). |
{id}_default_time_limit |
20 |
Per-batch time budget, in seconds. |
{id}_time_exceeded |
computed | Override whether the time budget is spent. |
{id}_memory_exceeded |
computed | Override whether the memory budget is spent. |
{id}_queue_lock_time |
60 |
Process lock duration, in seconds. |
{id}_cron_interval |
5 |
Health-check interval, in minutes. |
BasicAuth
If your site is behind BasicAuth, requests rely on the WordPress HTTP API and need credentials attached:
Upgrading from 1.x
The 2.0 release is a structural rewrite. The classes you extend (Async, Task) and their public methods
(push_to_queue(), set_queue(), save(), dispatch(), update(), delete(), cancel_process()) and every filter
are unchanged, so most consumers only need to bump the requirement.
What changed:
- PHP 7.4+ is now required (was 5.6); properties and signatures are typed.
- Persistence, load-guarding, and locking moved into injectable collaborators (
StoreInterface,ServerLimits,ProcessLock). The internal protected helpers from 1.x (is_queue_empty(),get_batch(),memory_exceeded(), …) were removed — overridetask()/complete()or inject a collaborator instead. set_queue()andsave()now type-hint their arguments.
Development
Credits
- A forked, modernised library of WP Background Processing.
- Maintained by Joel James