PHPackages                             phpnomad/tasks - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpnomad/tasks

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpnomad/tasks
==============

2.1.1(3w ago)03.9k2MITPHPCI passing

Since May 21Pushed 3w ago2 watchersCompare

[ Source](https://github.com/phpnomad/tasks)[ Packagist](https://packagist.org/packages/phpnomad/tasks)[ Docs](https://github.com/phpnomad/tasks)[ RSS](/packages/phpnomad-tasks/feed)WikiDiscussions main Synced today

READMEChangelog (4)DependenciesVersions (10)Used By (2)

phpnomad/tasks
==============

[](#phpnomadtasks)

[![Latest Version](https://camo.githubusercontent.com/dc0160c66b77ca568e172c78de0f8ba07f65a578a9da41cd510facb378c284a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f7461736b732e737667)](https://packagist.org/packages/phpnomad/tasks)[![Total Downloads](https://camo.githubusercontent.com/8447a39ffbbd6304a8976fe848b219af8e59a72e0adb1fb1622aee5c0059ab41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f7461736b732e737667)](https://packagist.org/packages/phpnomad/tasks)[![PHP Version](https://camo.githubusercontent.com/44de8be0a0be6b642677ee4bf187c1cf4e539436e70dc1f634182a615a3aebc0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f7461736b732e737667)](https://packagist.org/packages/phpnomad/tasks)[![License](https://camo.githubusercontent.com/1af7f6548c58871cf48b23ef1b60c05d817b8160256c22ab5781c36b9f79ef8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f7461736b732e737667)](https://packagist.org/packages/phpnomad/tasks)

`phpnomad/tasks` provides interfaces for declaring background and scheduled tasks in PHP applications. A task is a serializable value object with a stable id and a `toPayload()` / `fromPayload()` round trip, which means you can dispatch one now and let a worker, a queue, or the platform's scheduler reconstruct it and run it later.

The dispatching strategy is pluggable. A concrete implementation decides whether a task runs immediately, lands on a Redis queue for a background worker to pick up, or gets registered with the host platform's scheduler (like WordPress cron). Your task classes and their handlers stay the same either way. This package is interfaces only and has zero runtime dependencies. For a working queue, also install a concrete implementation. The recommended one is [`phpnomad/redis-task-integration`](https://packagist.org/packages/phpnomad/redis-task-integration), a Redis-backed worker queue. The package is used in production by [Siren](https://sirenaffiliates.com) and other PHPNomad applications.

Installation
------------

[](#installation)

```
composer require phpnomad/tasks
```

For a working queue, also install the Redis integration:

```
composer require phpnomad/redis-task-integration
```

Quick Start
-----------

[](#quick-start)

Define a task. It needs a stable identifier and a payload that can survive a trip through JSON.

```
use PHPNomad\Tasks\Exceptions\TaskCreateFailedException;
use PHPNomad\Tasks\Interfaces\Task;

class SendWelcomeEmail implements Task
{
    public function __construct(
        public readonly int $userId
    ) {}

    public static function getId(): string
    {
        return 'user.send_welcome_email';
    }

    public function toPayload(): array
    {
        return ['userId' => $this->userId];
    }

    /**
     * @throws TaskCreateFailedException
     */
    public static function fromPayload(array $payload): static
    {
        return new static($payload['userId']);
    }
}
```

Write a handler that runs the task. The `@implements` tag lets your static analyzer narrow `$task` to the concrete class.

```
use PHPNomad\Tasks\Interfaces\CanHandleTask;
use PHPNomad\Tasks\Interfaces\Task;

/**
 * @implements CanHandleTask
 */
class SendWelcomeEmailHandler implements CanHandleTask
{
    public function __construct(
        protected UserDatastore $users,
        protected EmailService $email
    ) {}

    public function handle(Task $task): void
    {
        $user = $this->users->find($task->userId);

        $this->email->send($user->getEmail(), 'Welcome!');
    }
}
```

Register the task-to-handler mapping on an initializer so the bootstrapper can wire it up.

```
use PHPNomad\Tasks\Interfaces\HasTaskHandlers;

class MyAppInitializer implements HasTaskHandlers
{
    public function getTaskHandlers(): array
    {
        return [
            SendWelcomeEmail::class => SendWelcomeEmailHandler::class,
        ];
    }
}
```

Dispatch the task from wherever the work is triggered. Inject `TaskStrategy` and call `dispatch()`.

```
use PHPNomad\Tasks\Interfaces\TaskStrategy;

class UserService
{
    public function __construct(
        protected UserDatastore $users,
        protected TaskStrategy $tasks
    ) {}

    public function createUser(string $email): User
    {
        $user = $this->users->create(['email' => $email]);

        $this->tasks->dispatch(new SendWelcomeEmail($user->getId()));

        return $user;
    }
}
```

The strategy chosen at bootstrap decides whether the task runs immediately, lands on a queue for a worker to pick up, or gets registered with the host scheduler. `SendWelcomeEmail` and `SendWelcomeEmailHandler` do not care which.

Key Concepts
------------

[](#key-concepts)

- `Task`: serializable value object identified by a static `getId()` string with a round-trip payload
- `TaskStrategy`: the dispatcher interface responsible for running, enqueueing, or scheduling a task
- `CanHandleTask`: the contract a handler implements to process a task
- `HasTaskHandlers`: initializer interface modules implement to register their task-to-handler mappings
- `IsIdempotent`: optional marker for tasks that must not double-run, with a deterministic key and a TTL
- `IdempotencyStore`: contract for the backing store that suppresses replays and concurrent double-runs

Documentation
-------------

[](#documentation)

Full documentation for PHPNomad, including the bootstrapping guide and the broader framework reference, lives at [phpnomad.com](https://phpnomad.com).

License
-------

[](#license)

MIT. See [LICENSE.txt](LICENSE.txt).

###  Health Score

47

↑

FairBetter than 93% of packages

Maintenance95

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.4% 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 ~179 days

Total

4

Last Release

22d ago

Major Versions

1.0.0 → 2.0.02025-05-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e6206223bd6f2a57b8ac80605b1b5c3521faaec18ad3f20f25fb728a9a13784?d=identicon)[tstandiford](/maintainers/tstandiford)

---

Top Contributors

[![alexstandiford](https://avatars.githubusercontent.com/u/8210827?v=4)](https://github.com/alexstandiford "alexstandiford (14 commits)")[![malayladu](https://avatars.githubusercontent.com/u/708174?v=4)](https://github.com/malayladu "malayladu (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

background-jobsframeworkphpphpnomadplatform-agnosticschedulertasks

### Embed Badge

![Health badge](/badges/phpnomad-tasks/health.svg)

```
[![Health](https://phpackages.com/badges/phpnomad-tasks/health.svg)](https://phpackages.com/packages/phpnomad-tasks)
```

###  Alternatives

[spatie/error-solutions

This is my package error-solutions

6764.5M18](/packages/spatie-error-solutions)[galacticlabs/disable-compare-products

Disable compare products functionality

1665.9k](/packages/galacticlabs-disable-compare-products)

PHPackages © 2026

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