PHPackages                             nunomaduro/pokio - 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. [API Development](/categories/api)
4. /
5. nunomaduro/pokio

ActiveLibrary[API Development](/categories/api)

nunomaduro/pokio
================

Pokio is a dead simple asynchronous API for PHP that just works

v0.1.2(4mo ago)711867.2k↑11.1%383MITPHPPHP ^8.3.0CI passing

Since Jun 7Pushed 4mo ago18 watchersCompare

[ Source](https://github.com/nunomaduro/pokio)[ Packagist](https://packagist.org/packages/nunomaduro/pokio)[ Fund](https://www.paypal.com/paypalme/enunomaduro)[ GitHub Sponsors](https://github.com/nunomaduro)[ RSS](/packages/nunomaduro-pokio/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (4)Used By (3)

 [ ![Overview Pokio](/art/banner.jpg) ](https://youtu.be/JUDQuymlsh0)

> **Caution**: This package is a **work in progress** and it manipulates process lifecycles using low-level and potentially unsafe techniques such as FFI for inter-process communication, and preserving state across process spawns. It is intended strictly for internal use (e.g., performance optimizations in Pest). **Don't use this in production or use at your own risk**—no guarantees are provided.

[   ![Logo for pokio](art/header-light.png) ](https://nunomaduro.com/)Pokio
=====

[](#pokio)

 [![Build Status](https://github.com/nunomaduro/pokio/actions/workflows/tests.yml/badge.svg)](https://github.com/nunomaduro/pokio/actions) [![Total Downloads](https://camo.githubusercontent.com/ada8c9e7f2e6da5f13e7874663dc96e7a0d11d328fa1d63aca763ebfd79db980/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e756e6f6d616475726f2f706f6b696f)](https://packagist.org/packages/nunomaduro/pokio) [![Latest Stable Version](https://camo.githubusercontent.com/c8231a47898b76f021f60018fcda3a207ff284e875be8fbd724013a4815e9bf5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e756e6f6d616475726f2f706f6b696f)](https://packagist.org/packages/nunomaduro/pokio) [![License](https://camo.githubusercontent.com/73a77f424f0ab85d6e6c2d3779a46aecf9e0bcc51591fc07799dca688f22e8c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e756e6f6d616475726f2f706f6b696f)](https://packagist.org/packages/nunomaduro/pokio)

**Pokio** is a dead simple **Asynchronous API for PHP** that just works! Here is an example:

```
$promiseA = async(function () {
    sleep(2);

    return 'Task 1';
});

$promiseB = async(function () {
    sleep(2);

    return 'Task 2';
});

// just takes 2 seconds...
[$resA, $resB] = await([$promiseA, $promiseB]);

echo $resA; // Task 1
echo $resB; // Task 2
```

Behind-the-scenes, Pokio uses the **[PCNTL](https://www.php.net/manual/en/book.pcntl.php)** extension to fork the current process and run the given closure in a child process. This allows you to run multiple tasks concurrently, without blocking the main process.

Also, for communication between the parent and child processes, Pokio uses **[FFI](https://www.php.net/manual/en/book.ffi.php)** to create a shared memory segment, which allows you to share data between processes fast and efficiently.

However, unlike other libraries, if **PCNTL** or **FFI** are not available, Pokio will automatically fall back to sequential execution, so you can still use it without any issues.

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

[](#installation)

> **Requires [PHP 8.3+](https://php.net/releases/)**.

⚡️ Get started by requiring the package using [Composer](https://getcomposer.org):

```
composer require nunomaduro/pokio:^0.1
```

Usage
-----

[](#usage)

- `async`

The `async` global function returns a promise that will eventually resolve the value returned by the given closure.

```
$promise = async(function () {
    return 1 + 1;
});

var_dump(await($promise)); // int(2)
```

Similar to other promise libraries, Pokio allows you to chain methods to the promise (like `then`, `catch`, etc.).

The `then` method will be called when the promise resolves successfully. It accepts a closure that will receive the resolved value as its first argument.

```
$promise = async(fn (): int => 1 + 2)
    ->then(fn ($result): int => $result + 2)
    ->then(fn ($result): int => $result * 2);

$result = await($promise);
var_dump($result); // int(10)
```

Optionally, you may chain a `catch` method to the promise, which will be called if the given closure throws an exception.

```
$promise = async(function () {
    throw new Exception('Error');
})->catch(function (Throwable $e) {
    return 'Rescued: ' . $e->getMessage();
});

var_dump(await($promise)); // string(16) "Rescued: Error"
```

If you don't want to use the `catch` method, you can also use native `try/catch` block.

```
$promise = async(function () {
    throw new Exception('Error');
});

try {
    await($promise);
} catch (Throwable $e) {
    var_dump('Rescued: ' . $e->getMessage()); // string(16) "Rescued: Error"
}
```

Similar to the `catch` method, you may also chain a `finally` method to the promise, which will be called regardless of whether the promise resolves successfully or throws an exception.

```
$promise = async(function (): void {
    throw new RuntimeException('Exception 1');
})->finally(function () use (&$called): void {
    echo "Finally called\n";
});
```

If you return a promise from the closure, it will be awaited automatically.

```
$promise = async(function () {
    return async(function () {
        return 1 + 1;
    });
});

var_dump(await($promise)); // int(2)
```

- `await`

The `await` global function will block the current process until the given promise resolves.

```
$promise = async(function () {
    sleep(2);

    return 1 + 1;
});

var_dump(await($promise)); // int(2)
```

You may also pass an array of promises to the `await` function, which will be awaited simultaneously.

```
$promiseA = async(function () {
    sleep(2);

    return 1 + 1;
});

$promiseB = async(function () {
    sleep(2);

    return 2 + 2;
});

var_dump(await([$promiseA, $promiseB])); // array(2) { [0]=> int(2) [1]=> int(4) }
```

Instead of using the await function, you can also invoke the promise directly, which will return the resolved value of the promise.

```
$promise = async(fn (): int => 1 + 2);

$result = $promise();

var_dump($result); // int(3)
```

Follow Nuno
-----------

[](#follow-nuno)

- Follow the creator Nuno Maduro:
    - YouTube: **[youtube.com/@nunomaduro](https://youtube.com/@nunomaduro)** — Videos every week
    - Twitch: **[twitch.tv/nunomaduro](https://twitch.tv/nunomaduro)** — Live coding on Mondays, Wednesdays, and Fridays at 9PM UTC
    - Twitter / X: **[x.com/enunomaduro](https://x.com/enunomaduro)**
    - LinkedIn: **[linkedin.com/in/nunomaduro](https://www.linkedin.com/in/nunomaduro)**
    - Instagram: **[instagram.com/enunomaduro](https://www.instagram.com/enunomaduro)**
    - Tiktok: **[tiktok.com/@enunomaduro](https://www.tiktok.com/@enunomaduro)**

License
-------

[](#license)

**Pokio** was created by **[Nuno Maduro](https://twitter.com/enunomaduro)** under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance75

Regular maintenance activity

Popularity62

Solid adoption and visibility

Community30

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.1% 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 ~106 days

Total

3

Last Release

134d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86cfef5c1f5195df1a9db17a5f8ecb34455e1f0133a725de9acf7f2fb26ac6a1?d=identicon)[nunomaduro](/maintainers/nunomaduro)

---

Top Contributors

[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (86 commits)")[![c0nst4ntin](https://avatars.githubusercontent.com/u/27086157?v=4)](https://github.com/c0nst4ntin "c0nst4ntin (38 commits)")[![tusharnain](https://avatars.githubusercontent.com/u/100490977?v=4)](https://github.com/tusharnain "tusharnain (8 commits)")[![parkourben99](https://avatars.githubusercontent.com/u/7295774?v=4)](https://github.com/parkourben99 "parkourben99 (3 commits)")[![arditqerosi](https://avatars.githubusercontent.com/u/65768218?v=4)](https://github.com/arditqerosi "arditqerosi (2 commits)")[![sediqzada94](https://avatars.githubusercontent.com/u/29443310?v=4)](https://github.com/sediqzada94 "sediqzada94 (2 commits)")[![SvenVanderwegen](https://avatars.githubusercontent.com/u/18567509?v=4)](https://github.com/SvenVanderwegen "SvenVanderwegen (2 commits)")[![Chris53897](https://avatars.githubusercontent.com/u/7104259?v=4)](https://github.com/Chris53897 "Chris53897 (1 commits)")[![adb-tusharnain](https://avatars.githubusercontent.com/u/181193362?v=4)](https://github.com/adb-tusharnain "adb-tusharnain (1 commits)")

---

Tags

phpasynchronouslibrarypokio

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nunomaduro-pokio/health.svg)

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

###  Alternatives

[maxbeckers/amazon-alexa-php

Php library for amazon echo (alexa) skill development.

11554.0k2](/packages/maxbeckers-amazon-alexa-php)[ontraport/sdk-php

ONTRAPORT PHP Library

19360.5k2](/packages/ontraport-sdk-php)

PHPackages © 2026

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