Download the PHP package shewa/wp-job-queue without Composer

On this page you can find all versions of the php package shewa/wp-job-queue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-job-queue

WP Job Queue

A reusable WordPress background job queue powered by WP-Cron. Jobs are stored in a custom database table, processed one step at a time, report progress to the admin UI, and can be cancelled while running.

Requirements

Installation

On plugin activation, install the database table:

Quick start


Architecture

Component Responsibility
Bootstrap Registers jobs, cron hooks, AJAX handlers, and runs DB upgrades
JobRegistry Maps job type strings (e.g. export_websites) to PHP classes
JobManager Public API: dispatch, process, cancel, list, and get jobs
JobRepository All reads/writes to the {prefix}wp_job_queue_jobs table
CronScheduler Schedules and runs the WP-Cron worker every minute
AjaxHandler REST-like AJAX endpoints for polling and cancelling from JavaScript
AbstractJob Base class your job handlers extend

How it works under the hood

WP Job Queue uses a step-based processing model. Each job is not one long-running task — it is a record in the database that advances one small chunk of work per execution. This fits WordPress well because PHP requests and WP-Cron ticks are short-lived.

Lifecycle

  1. Dispatch — JobManager::dispatch() validates the job class, checks that the type is registered, ensures no duplicate active job exists for the same type/user, inserts a pending row, and schedules WP-Cron.
  2. Schedule — CronScheduler::schedule() registers a recurring event on the wp_job_queue_worker hook (every minute). spawn_cron() is also called to nudge WP-Cron immediately.
  3. Worker tick — On each cron run (and optionally during admin requests), JobManager::processNext() loads the oldest pending or running job and executes one step.
  4. Step execution — The registered job class is instantiated and handle( JobRecord $job ) is called. It returns a JobResult telling the manager what to do next.
  5. State update — Based on the result:
    • JobResult::continue() — update payload/progress, keep status running, increment current_step
    • JobResult::complete() — set status completed, store final result JSON, set progress to 100
    • JobResult::failed() — set status failed, store the error message
  6. Idle cleanup — When no pending or running jobs remain, the cron event is unscheduled to avoid unnecessary overhead.

Processing triggers

Jobs advance through two mechanisms:

Trigger When Purpose
WP-Cron (wp_job_queue_worker) Every minute while jobs are active Primary background worker
Admin init (maybeProcessOnAdmin) Each admin page load by a privileged user Helps local/dev sites where cron is unreliable

Concurrency model

Error handling

WP-Cron note

WordPress cron only fires when someone visits the site. For production, either prompt users to keep the admin page open while jobs run, or configure a real server cron:


Database table

Table name: {prefix}wp_job_queue_jobs (override with the wp_job_queue_table_name filter)

Column Description
id Auto-increment primary key
job_type Unique job identifier (from getType())
status pending, running, completed, failed, or cancelled
payload JSON data passed between steps
progress 0–100 percentage
current_step Number of completed steps
total_steps Total steps if known (0 otherwise)
result JSON output when completed
error_message Error text when failed
status_message Human-readable progress message
user_id User who dispatched the job
created_at / updated_at Timestamps
started_at / completed_at Set when job starts and reaches a terminal state

The table is created by Migrator::install() and auto-upgraded on boot via Migrator::maybeUpgrade().


Creating a job

Extend AbstractJob and implement handle(). Each call to handle() should process one step and return a JobResult.

Register the class when booting:


JobResult API

Method When to use
JobResult::continue( $payload, $progress, $message ) More steps remain
JobResult::complete( $result, $message ) Job finished successfully
JobResult::failed( $error ) Job failed

Status constants (for comparisons):

Constant Value
JobResult::STATUS_CONTINUE continue
JobResult::STATUS_COMPLETE complete
JobResult::STATUS_FAILED failed

Dispatching jobs


Checking job status

PHP

JobStatus::active() returns [ 'pending', 'running' ].
JobStatus::terminal() returns [ 'completed', 'failed', 'cancelled' ].

AJAX (JavaScript polling)

All endpoints require manage_options and a valid nonce.

Action Parameters Description
wp_job_queue_status job_id, wp_job_queue_nonce Get a single job
wp_job_queue_cancel job_id, wp_job_queue_nonce Cancel a job
wp_job_queue_list job_type, status[], wp_job_queue_nonce List jobs

Nonce action: wp_job_queue
Nonce field: wp_job_queue_nonce

Example JavaScript poll:


Cancelling jobs

Jobs should check for cancellation at the start of handle() if they need to stop mid-run:


Example: multi-step API pagination

A common pattern is fetching paginated API results across multiple steps:


Adding new jobs

  1. Create a class extending AbstractJob in your plugin (e.g. inc/Jobs/ScrapeEmailsJob.php).
  2. Implement getType(), optionally override getLabel(), and implement handle().
  3. Register the class in your bootstrap config passed to Bootstrap::init().
  4. Dispatch from your feature's AJAX handler or admin action.
  5. Use the built-in AJAX endpoints to poll progress and cancel from the frontend.

Filters

Filter Description
wp_job_queue_table_name Override the database table name

PHP compatibility

This package targets PHP 7.4 through 8.5. It uses features available in PHP 7.4 (typed properties, nullable types, void return types) and avoids syntax that would break on older runtimes:


Repository

https://github.com/shewa12/wp-job-queue

License

MIT


All versions of wp-job-queue with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4 <=8.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package shewa/wp-job-queue contains the following files

Loading the files please wait ...