mr-rijal / laravel-pipeline
Lightweight workflow and automation pipeline for Laravel
Requires
- php: ^8.2
- illuminate/contracts: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- larastan/larastan: ^2|^3
- laravel/pint: ^1
- orchestra/testbench: ^9|^10
- phpunit/phpunit: ^9|^10
This package is auto-updated.
Last update: 2026-02-25 06:10:37 UTC
README
Lightweight, enterprise-ready pipeline workflow engine for Laravel Supports sequential, parallel, and flow-based execution with debug timeline, retries, timeouts, and queued parallelism.
📦 Installation
Install via Composer:
composer require mr-rijal/laravel-pipeline
Laravel auto-discovers the service provider. No manual registration required.
🛠️ Features
- Sequential, parallel, and flow pipelines
- Debug timeline with per-step execution metrics
- Retry failed steps with configurable attempts
- Step timeout support
- Parallel execution with optional queue (Redis/Horizon)
- Shared
LaravelPipelineContextfor passing data between steps - Works with Closures or classes implementing
handle(LaravelPipelineContext $ctx) - PHPUnit + Testbench ready
- Lightweight, production-grade performance
🔧 Usage
1️⃣ Basic Sequential Steps
use MrRijal\LaravelPipeline\Facades\LaravelPipeline; use MrRijal\LaravelPipeline\DTO\LaravelPipelineContext; LaravelPipeline::steps([ fn (LaravelPipelineContext $ctx) => $ctx->set('foo', 'bar'), fn (LaravelPipelineContext $ctx) => $ctx->get('foo'), // returns 'bar' ])->run();
2️⃣ Flow (Continue on Fail)
$results = LaravelPipeline::flow([ fn() => true, fn() => false, // continue even if fails fn() => true ]);
3️⃣ Parallel (Run All at Once)
$results = LaravelPipeline::parallel([ StepOne::class, StepTwo::class, ]);
🧰 Advanced Features
Debug Timeline
$pipeline = LaravelPipeline::steps([ StepOne::class, StepTwo::class, ])->with(['user_id' => 5]); $pipeline->run(); // or wrap in try/catch if steps may throw $results = $pipeline->getResults(); foreach ($results as $step) { echo "{$step->name}: " . ($step->success ? '✔' : '✘') . " ({$step->time}ms)\n"; }
Output Example:
StepOne: ✔ (0.12ms)
StepTwo: ✘ (0.21ms) - Exception message if failed
Retry & Timeout
Retry and timeout are currently supported via the runStep() method when building custom pipelines; a more convenient array format [Step::class, 'retry' => 3, 'timeout' => 500] is planned for a future release. See docs for details.
Queued Parallel Execution
LaravelPipeline::parallel([ StepOne::class, StepTwo::class ], queue: true); // Dispatches steps to Laravel queue
- Works with Laravel Redis queues or Horizon
- Steps executed concurrently without blocking main thread
Shared Pipeline Context
LaravelPipelineContext allows passing data between steps:
LaravelPipeline::steps([ fn (LaravelPipelineContext $ctx) => $ctx->set('user_id', 123), fn (LaravelPipelineContext $ctx) => $ctx->get('user_id'), // 123 ])->run();
⚡ Benchmark
vendor/bin/phpunit --filter BenchmarkTest
Typical performance (3-step pipeline):
- Sequential: < 10ms (micro-benchmark)
- Memory usage: negligible
- Parallel queued execution depends on queue worker speed
💡 Step Types
- Closure
fn (LaravelPipelineContext $ctx) => true
- Class with handle() (class name or instance)
class StepOne { public function handle(LaravelPipelineContext $ctx): bool { return true; } }
- Boolean literal
true // simple pass/fail (e.g. in flow())
🔧 Testing
Run PHPUnit tests:
vendor/bin/phpunit
Includes:
- Sequential / flow / parallel tests
- Micro-benchmark tests
📝 Notes
- Make sure queue workers are running when using
parallel(queue: true) - Use
getResults()for detailed debugging or logging - Step names are auto-detected from class name or “Closure”
💖 Sponsor
If you find this project helpful, please consider sponsoring my open source work to help sustain development and maintenance!
Thank you for supporting open source software.
🔖 License
MIT © Prashant Rijal