PHPackages                             dmamontov/asynctask-7 - 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. dmamontov/asynctask-7

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

dmamontov/asynctask-7
=====================

AsyncTask enables proper and easy use of the thread. This class allows to perform background operations and publish results on the thread without having to manipulate threads and/or handlers.

2.0.13(7y ago)1313.1k2BSD-3-ClausePHPPHP &gt;=7.0.0CI failing

Since Feb 4Pushed 6y ago2 watchersCompare

[ Source](https://github.com/dmamontov/asynctask-7)[ Packagist](https://packagist.org/packages/dmamontov/asynctask-7)[ Docs](https://bringer.pro/)[ RSS](/packages/dmamontov-asynctask-7/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/49955b1a4a0639d4406aa55a68fbae25d01111ba1adb6fd0783e04699a9491a1/68747470733a2f2f7472617669732d63692e6f72672f646d616d6f6e746f762f6173796e637461736b2d372e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dmamontov/asynctask-7)[![Latest Stable Version](https://camo.githubusercontent.com/02ad201b1d306f88021005f232edf67aab6ee09ca7ee7a340d02a7aa5d3873aa/68747470733a2f2f706f7365722e707567782e6f72672f646d616d6f6e746f762f6173796e637461736b2d372f762f737461626c652e737667)](https://packagist.org/packages/dmamontov/asynctask-7)[![License](https://camo.githubusercontent.com/2477b6477f5454d25a33552b05f02642e43ef2ba44b8dcf2d6ee6cb9cbd048fc/68747470733a2f2f706f7365722e707567782e6f72672f646d616d6f6e746f762f6173796e637461736b2d372f6c6963656e73652e737667)](https://packagist.org/packages/dmamontov/asynctask-7)[![Total Downloads](https://camo.githubusercontent.com/21a387c97750e719d28feae17f162755bd5f83d84c3bd4d926b6ff46cce8adfe/68747470733a2f2f706f7365722e707567782e6f72672f646d616d6f6e746f762f6173796e637461736b2d372f646f776e6c6f616473)](https://packagist.org/packages/dmamontov/asynctask-7)[![PHP Classes](https://camo.githubusercontent.com/8b4a94a79f43f44687b40e0a91a226a5b6d929b69cba415d01253b2343065bf0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d636c61737365732d626c75652e737667)](https://www.phpclasses.org/package/11064-PHP-Execute-parallel-task-using-a-sub-class.html)

AsyncTask
=========

[](#asynctask)

AsyncTask enables proper and easy use of the thread. This class allows to perform background operations and publish results on the thread without having to manipulate threads and/or handlers.

[The early class](https://github.com/dmamontov/asynctask) implementation supports PHP 5.3, but does not support what is implemented in this class.

Requirements
------------

[](#requirements)

- `PHP` version `~7.1.0`
- Module installed `pcntl` and `posix`
- All functions `pcntl`, `posix` removed from the directive `disable_functions`
- `SharedMemoryAdapter`:

    - All functions `shm` removed from the directive `disable_functions`

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

[](#installation)

1. Install [composer](https://getcomposer.org/download/)
2. Follow in the project folder:

```
composer require dmamontov/asynctask-7 ~2.0.13
```

In config `composer.json` your project will be added to the library `dmamontov/asynctask-7`, who settled in the folder `vendor/`. In the absence of a config file or folder with vendors they will be created.

If before your project is not used `composer`, connect the startup file vendors. To do this, enter the code in the project:

```
require 'path/to/vendor/autoload.php';
```

Adapter list
------------

[](#adapter-list)

- `SharedMemory` - working
- `FileSystem` - in the process
- `Redis` - in the process

**Offer adapters that are missing. We develop!**

Examples
--------

[](#examples)

### Example of work

[](#example-of-work)

```
use AsyncTask\{
    AsyncTask,
    Collection
};

class TestTask extends AsyncTask
{
    protected function onPreExecute(Collection $collection)
    {
    }

    protected function doInBackground(Collection $collection)
    {
        return 'My First Task';
    }

    protected function onPostExecute($result)
    {
        echo $result;
    }

    protected function publishProgress()
    {
        echo rand(0,9) . PHP_EOL;
    }
}

$task = new TestTask();
$task
    ->setTitle('TestTask')
    ->execute(new Collection);
```

### Task Example

[](#task-example)

```
use AsyncTask\AsyncTask;
use AsyncTask\Collection;

class ExampleTask extends AsyncTask
{
    /**
     * Optional method.
     */
    protected function onPreExecute(Collection $collection)
    {
        return $collection;
    }

    /**
     * Required method.
     */
    protected function doInBackground(Collection $collection)
    {
        return $collection;
    }

    /**
     * Optional method.
     * With this method, an additional process is created.
     */
    protected function publishProgress()
    {
    }

    /**
     * Optional method.
     */
    protected function onPostExecute($result)
    {
    }

    /**
     * Optional method.
     */
    protected function onCancelled()
    {
    }
}
```

### Adapter Example

[](#adapter-example)

```
use AsyncTask\Adapter;
use AsyncTask\Interfaces\AdapterInterface;

class ExampleAdapter extends Adapter implements AdapterInterface
{

    /**
     * Required method.
     */
    public function init(): AdapterInterface
    {
        return $this;
    }

    /**
     * Required method.
     */
    public function finish(): AdapterInterface
    {
        return $this;
    }

    /**
     * Required method.
     */
    public function clean(bool $parent = false): AdapterInterface
    {
        return $this;
    }

    /**
     * Required method.
     */
    public function has($key, bool $parent = false): bool
    {
        return false;
    }

    /**
     * Required method.
     */
    public function remove($key, bool $parent = false): bool
    {
        return true;
    }

    /**
     * Required method.
     */
    public function get($key, bool $parent = false)
    {
        return null;
    }

    /**
     * Required method.
     */
    public function write($key, $val, bool $parent = false): AdapterInterface
    {
        return $this;
    }
}
```

ToDo
----

[](#todo)

- More tests.
- More adapters.
- Class for managing running processes.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~3 days

Total

2

Last Release

2651d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5955726?v=4)[Dmitry Mamontov](/maintainers/dmamontov)[@dmamontov](https://github.com/dmamontov)

---

Top Contributors

[![dmamontov](https://avatars.githubusercontent.com/u/5955726?v=4)](https://github.com/dmamontov "dmamontov (4 commits)")

---

Tags

asynchronoustaskbackgroundwork days

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dmamontov-asynctask-7/health.svg)

```
[![Health](https://phpackages.com/badges/dmamontov-asynctask-7/health.svg)](https://phpackages.com/packages/dmamontov-asynctask-7)
```

###  Alternatives

[react/react

ReactPHP: Event-driven, non-blocking I/O with PHP.

9.1k3.6M63](/packages/react-react)[react/event-loop

ReactPHP's core reactor event loop that libraries can use for evented I/O.

1.3k139.6M664](/packages/react-event-loop)[phing/phing

PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

1.2k21.7M876](/packages/phing-phing)[cocur/background-process

Start processes in the background that continue running when the PHP process exists.

2971.9M12](/packages/cocur-background-process)[laravel-admin-ext/scheduling

Task scheduling extension for laravel-admin

93247.1k6](/packages/laravel-admin-ext-scheduling)[arara/process

Provides a better API to work with processes on Unix-like systems

16861.7k2](/packages/arara-process)

PHPackages © 2026

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