Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pokio Laravel Package

nunomaduro/pokio

Pokio is a simple async API for PHP 8.3+ using pcntl forks and FFI shared memory to run closures concurrently and await results. Falls back to sequential execution if extensions aren’t available. Experimental/unsafe; intended for internal use, not production.

View on GitHub
Deep Wiki
Context7

Pokio is a dead-simple asynchronous API for PHP that runs closures concurrently and lets you await their results with minimal ceremony. It’s built for internal tooling and performance work, using low-level process tricks—use at your own risk and avoid production.

  • Run tasks in parallel via PCNTL process forking
  • Fast parent/child communication using FFI shared memory
  • Familiar async() / await() workflow for coordinating promises
  • Automatic fallback to sequential execution when PCNTL/FFI aren’t available
  • Designed to keep overhead low for test runners and CLI workloads
Frequently asked questions about Pokio
Can I use Pokio in Laravel Artisan commands to speed up batch processing?
Yes, Pokio is perfect for parallelizing Artisan commands. For example, you can process chunks of data concurrently by wrapping tasks in `async()` and awaiting results with `await()`. Just ensure your closures are stateless or reinitialize Laravel dependencies inside them, as child processes don’t share the parent’s state.
What Laravel versions support Pokio, and do I need PHP 8.3+?
Pokio requires PHP 8.3+ and is best suited for Laravel 10+. If you’re using an older Laravel version (e.g., 8.x), you’ll need to upgrade PHP or avoid Pokio, as it won’t work without the required PHP features. The package explicitly targets modern PHP for its concurrency model.
How do I install Pokio in a Laravel project?
Install via Composer: `composer require nunomaduro/pokio`. No additional configuration is needed for basic usage. For Laravel-specific integration, bind the `Async` class in a service provider if you want global access, like `$this->app->singleton('async', fn() => new Async());` for CLI-only use.
Will Pokio work on shared hosting or Windows?
Pokio defaults to sequential execution if PCNTL or FFI aren’t available, which is common on shared hosting or Windows. While it’ll still run, performance gains vanish. Test thoroughly on unsupported platforms, as behavior may differ. Windows users should avoid relying on parallelism entirely.
Can I use Pokio for Laravel test suites like Pest or PHPUnit?
Pokio is used internally by its author for Pest, but it’s experimental for testing. Parallel test execution is possible, but ensure tests are isolated and stateless. Child processes won’t share Laravel’s service container, so avoid shared dependencies like database connections or cached state.
What happens if a child process crashes or times out?
Pokio doesn’t automatically handle zombie processes, so you may need to manually reap children with `pcntl_wait()` or enable PHP ticks (`declare(ticks=1)`). Wrap `await()` calls in try-catch blocks to catch exceptions from child processes, as errors may not propagate cleanly.
Is Pokio safe for production use in Laravel applications?
No, Pokio is explicitly labeled as experimental and unsafe for production. It manipulates low-level process and memory operations (PCNTL/FFI) that can cause instability, leaks, or corruption. Use it only for internal tooling, CLI scripts, or non-critical performance tasks.
How does Pokio handle shared memory between parent and child processes?
Pokio uses FFI to create shared memory segments for fast parent-child communication. However, this isn’t thread-safe, so concurrent writes can corrupt data. Stick to immutable data or serialize/deserialize complex objects to avoid risks. Avoid shared state unless you’re certain of its safety.
Are there alternatives to Pokio for async tasks in Laravel?
For production-ready async, consider Laravel Queues (database/Redis) or libraries like Amp or ReactPHP for event loops. For CLI concurrency, `popen()` or `pcntl_fork()` with manual process management are alternatives, but Pokio offers a simpler async/await syntax. Avoid unsafe libraries in production.
How do I debug Pokio if tasks hang or behave unexpectedly?
Start by checking if PCNTL/FFI are enabled (`php -m | grep pcntl`). Use `declare(ticks=1)` to ensure child processes are reaped. Log output from child processes with `error_log()` or `fwrite(STDERR, ...)` inside closures. If using Laravel, ensure no global state (e.g., DB connections) is shared across processes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport