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

Async Laravel Package

spatie/async

Run PHP tasks in parallel with a simple Pool API built on PCNTL. Add closures, handle results via then/catch, and wait for completion. Ideal for speeding up batch jobs, CPU-heavy work, and IO-bound processing with multiple processes.

View on GitHub
Deep Wiki
Context7

Easily run code asynchronously

Frequently asked questions about Async
How do I install spatie/async in a Laravel project?
Run `composer require spatie/async` in your project directory. No additional configuration is needed unless you’re using Windows, where you’ll need WSL or a custom setup for PCNTL support.
Can I use spatie/async for Laravel queue jobs?
Yes, but it’s not a direct replacement. Use it for CPU-bound tasks within a job’s handle method, then dispatch the job to Laravel’s queue system. Async runs in parallel *within* the job, not across workers.
What Laravel versions does spatie/async support?
The package is framework-agnostic but tested with Laravel 8.x, 9.x, and 10.x. It works with any PHP 8.0+ app, including vanilla PHP or Symfony projects.
How do I handle errors in parallel processes?
Use the `catch()` method on each task to log exceptions. For critical tasks, wrap the `Pool::wait()` call in a try-catch and log errors to a service like Sentry or Laravel’s logging system.
Is spatie/async suitable for Windows-hosted Laravel apps?
No, PCNTL is not natively supported on Windows. Use WSL (Windows Subsystem for Linux) or a Linux-based hosting environment like Forge, Heroku, or shared hosting with PCNTL enabled.
Can I dynamically add tasks to a Pool while it’s running?
Yes, tasks can be added to the Pool at any time before calling `wait()`. However, all tasks must complete before the Pool resolves, so avoid adding tasks after `wait()` is called.
How does spatie/async compare to Laravel’s queue system?
Async runs tasks in parallel *within a single request* (true parallelism via PCNTL), while Laravel queues distribute jobs across workers (concurrency). Use Async for CPU-heavy batch jobs and queues for background tasks.
What’s the best way to monitor parallel processes?
Use `pcntl_signal_dispatch()` for custom signal handling or tools like `htop`/`strace` to monitor child processes. For Laravel, log process IDs and execution times via the `then()`/`catch()` callbacks.
Does spatie/async support retries for failed tasks?
No, it lacks built-in retry logic. For resilience, combine it with Laravel’s queue system or manually wrap tasks in retry loops using `try-catch` and a counter.
Can I use spatie/async for API rate-limited tasks (e.g., parallel API calls)?
Yes, but throttle the Pool size (e.g., `Pool::create()->pool(5)`) to avoid hitting rate limits. Use `then()` to handle responses and `catch()` to log throttling errors.
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