Download the PHP package nunomaduro/pokio without Composer
On this page you can find all versions of the php package nunomaduro/pokio. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nunomaduro/pokio
More information about nunomaduro/pokio
Files in nunomaduro/pokio
Package pokio
Short Description Pokio is a dead simple asynchronous API for PHP that just works
License MIT
Informations about the package pokio
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.
Pokio
Pokio is a dead simple Asynchronous API for PHP that just works! Here is an example:
Behind-the-scenes, Pokio uses the PCNTL 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 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
Requires PHP 8.3+.
⚡️ Get started by requiring the package using Composer:
Usage
async
The async
global function returns a promise that will eventually resolve the value returned by the given closure.
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.
Optionally, you may chain a catch
method to the promise, which will be called if the given closure throws an exception.
If you don't want to use the catch
method, you can also use native try/catch
block.
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.
If you return a promise from the closure, it will be awaited automatically.
await
The await
global function will block the current process until the given promise resolves.
You may also pass an array of promises to the await
function, which will be awaited simultaneously.
Instead of using the await function, you can also invoke the promise directly, which will return the resolved value of the promise.
Follow Nuno
- Follow the creator Nuno Maduro:
- YouTube: youtube.com/@nunomaduro — Videos every weekday
- Twitch: twitch.tv/enunomaduro — Streams (almost) every weekday
- Twitter / X: x.com/enunomaduro
- LinkedIn: linkedin.com/in/nunomaduro
- Instagram: instagram.com/enunomaduro
- Tiktok: tiktok.com/@enunomaduro
License
Pokio was created by Nuno Maduro under the MIT license.