Weave 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

Pipeline Laravel Package

amphp/pipeline

amphp/pipeline provides fiber-safe concurrent iterators and collection operators for AMPHP event-driven PHP apps. Consume asynchronous sets with foreach, yield from, or iterator_to_array across multiple fibers. Requires PHP 8.1+; install via composer require amphp/pipeline.

View on GitHub
Deep Wiki
Context7

amphp/pipeline provides concurrent iterators and collection operators for AMPHP’s fiber-based asynchronous PHP ecosystem. It introduces a fiber-safe ConcurrentIterator that can be consumed by multiple fibers simultaneously—unlike standard Iterator instances—while still supporting foreach, yield from, and iterator_to_array().

  • Concurrent consumption: Safely share one iterator across multiple fibers.
  • Familiar interface: Works with standard iteration constructs and manual continue()/getValue() calls.
  • Async pipelines: Build and transform asynchronous sets using collection operators.
  • PHP 8.1+: Leverages fibers and coroutines for event-driven concurrency.
  • Composer-ready: Install easily with composer require amphp/pipeline.
Frequently asked questions about Pipeline
Can I use amphp/pipeline in Laravel without AMPHP or Swoole?
No, this package requires a fiber-compatible runtime like AMPHP, Swoole, or ReactPHP. For traditional Laravel (CLI/FPM), use it with worker pools like RoadRunner or Spiral Framework. If you’re not using fibers, consider synchronous alternatives like Laravel Collections or queue-based parallelism via spatie/async.
How do I process database results asynchronously with Laravel and amphp/pipeline?
Replace `DB::get()` with `DB::cursor()` to stream rows, then wrap it in a pipeline: `Pipeline::fromIterable(DB::cursor())->concurrent(5)->map(fn($row) => $row->process())->forEach(fn($result) => Log::info($result));`. This avoids loading all rows into memory at once.
Will amphp/pipeline work with Laravel Horizon for queue jobs?
Yes, but Horizon workers must run in a fiber-compatible environment (e.g., RoadRunner). Use `Pipeline::fromIterable(Job::all())->concurrent(10)->map(fn($job) => $job->handle())` to process jobs in parallel within a worker. For non-fiber setups, use spatie/async or Horizon’s built-in parallelism.
What’s the difference between `ConcurrentIterator` and Laravel Collections?
Laravel Collections are synchronous and single-threaded, while `ConcurrentIterator` enables fiber-safe, parallel processing across multiple fibers. Use Collections for simple transformations; use `amphp/pipeline` for async workflows like batch API calls or high-volume database exports where concurrency is critical.
How do I handle errors in a pipeline if a fiber fails?
Wrap pipeline operations in `try/catch` blocks. Exceptions propagate to the fiber consuming the iterator. For resilience, implement circuit-breaker patterns (e.g., retry failed jobs) or use `Pipeline::buffer()` to limit concurrent operations and prevent cascading failures.
Can I use amphp/pipeline for real-time event processing in Laravel?
Yes, transform event payloads asynchronously before dispatching: `Pipeline::fromIterable($events)->map(fn($event) => $event->sanitize())->forEach(fn($event) => event($event));`. This works with Laravel’s event system if your app runs in a fiber-compatible environment like RoadRunner.
What’s the performance impact of using concurrent iterators vs. synchronous loops?
Concurrent iterators introduce context-switching overhead, so benchmark against synchronous alternatives (e.g., `Collection::chunk()`). Use pipelines for I/O-bound tasks (e.g., API calls, DB queries) where parallelism outweighs the cost. For CPU-bound work, synchronous loops may still be faster.
How do I limit memory usage with large datasets in amphp/pipeline?
Use `Pipeline::buffer($size)` to cap concurrent operations, preventing memory spikes. For example, `Pipeline::fromIterable(DB::cursor())->buffer(100)->map(...)` ensures no more than 100 rows are processed concurrently. This is critical for rate-limited APIs or large exports.
Are there alternatives to amphp/pipeline for async Laravel workflows?
For non-fiber setups, use Laravel’s built-in queues (Horizon) or packages like `spatie/async` for parallel job processing. If you need fiber support, consider `reactphp/promise` or `swoole/async`, but `amphp/pipeline` is the most integrated solution for AMPHP’s concurrency model.
How do I migrate an existing Laravel app to use amphp/pipeline?
Start with a non-critical async workflow (e.g., image resizing). Replace `foreach ($items)` with `Pipeline::fromIterable($items)->foreach(fn($item) => ...)`. Gradually adopt it for queue jobs or database cursors. Use RoadRunner or Spiral Framework to manage fibers in production.
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.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections