PHPackages                             dalehurley/process-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. dalehurley/process-manager

ActiveLibrary[CLI &amp; Console](/categories/cli)

dalehurley/process-manager
==========================

A lightweight parallel process runner for PHP. Execute multiple scripts concurrently with configurable parallelism, timeouts, and result tracking.

v2.1.0(5mo ago)17113MITPHPPHP &gt;=8.2CI failing

Since Dec 5Pushed 5mo ago3 watchersCompare

[ Source](https://github.com/dalehurley/PHP-Process-Manager)[ Packagist](https://packagist.org/packages/dalehurley/process-manager)[ Docs](https://github.com/dalehurley/PHP-Process-Manager)[ GitHub Sponsors](https://github.com/dalehurley)[ RSS](/packages/dalehurley-process-manager/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

PHP Process Manager
===================

[](#php-process-manager)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7b963a0e90daee33a94bf8eb86d13582faf0424b30078ee103233f99557e84b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616c656875726c65792f70726f636573732d6d616e616765722e737667)](https://packagist.org/packages/dalehurley/process-manager)[![Total Downloads](https://camo.githubusercontent.com/f8cd564255a7ba89617c759abeebc91d358fc92e2ea475eda50c2b40359ad760/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64616c656875726c65792f70726f636573732d6d616e616765722e737667)](https://packagist.org/packages/dalehurley/process-manager)[![PHP Version](https://camo.githubusercontent.com/e6df90fa4b923fa0ace3419e3d455ad96c02d81a6f7b592e25cc079382ef9166/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64616c656875726c65792f70726f636573732d6d616e616765722e737667)](https://packagist.org/packages/dalehurley/process-manager)[![License](https://camo.githubusercontent.com/ace6c72497e24c8fa063698e50f4ba85d308657b18ef6b83decd5bb9d03f901f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64616c656875726c65792f70726f636573732d6d616e616765722e737667)](LICENSE)[![Tests](https://camo.githubusercontent.com/6e70803a672857ef5685783b5a942d1900f51eaa7327b53dab22115bbe7c4404/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64616c656875726c65792f5048502d50726f636573732d4d616e616765722f74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473)](https://github.com/dalehurley/PHP-Process-Manager/actions)

A lightweight **parallel process runner** for PHP. Execute multiple scripts or commands concurrently with configurable parallelism, timeouts, and real-time output tracking.

```
Sequential execution:        Parallel execution (3 concurrent):
┌────┐┌────┐┌────┐┌────┐┌────┐┌────┐    ┌────┐┌────┐
│ T1 ││ T2 ││ T3 ││ T4 ││ T5 ││ T6 │    │ T1 ││ T4 │
│ 5s ││ 5s ││ 5s ││ 5s ││ 5s ││ 5s │    │ 5s ││ 5s │
└────┘└────┘└────┘└────┘└────┘└────┘    ├────┤├────┤
         Total: 30 seconds              │ T2 ││ T5 │
                                        │ 5s ││ 5s │
                                        ├────┤├────┤
                                        │ T3 ││ T6 │
                                        │ 5s ││ 5s │
                                        └────┘└────┘
                                        Total: 10 seconds

```

---

Overview
--------

[](#overview)

### What is it?

[](#what-is-it)

PHP Process Manager is a **concurrent task runner** that spawns and manages multiple OS processes simultaneously. Instead of running tasks one after another (sequential), it executes them in parallel—dramatically reducing total execution time for batch operations.

Think of it as a simple **process pool** or **worker spawner**: you queue up scripts, set a concurrency limit, and the manager handles execution, monitoring, timeouts, and result collection.

### Who is it for?

[](#who-is-it-for)

AudienceUse Case**Backend developers**Batch processing, data imports/exports, scheduled jobs**DevOps engineers**Deployment scripts, server maintenance, multi-host operations**Data engineers**ETL pipelines, file processing, API data collection**QA engineers**Parallel test execution, load testing preparation**System administrators**Bulk operations, log processing, backup scripts### Why use it?

[](#why-use-it)

PHP is single-threaded by default. When you have independent tasks, running them sequentially wastes time:

ScenarioSequentialParallel (5 workers)Speedup10 API calls × 2s each20s~4s**5×**100 file imports × 1s each100s~20s**5×**50 email sends × 0.5s each25s~5s**5×****This package is ideal when you need to:**

- Run the same script multiple times with different inputs
- Execute multiple independent scripts as part of a workflow
- Process batches of work faster by parallelising
- Add timeout protection to unreliable external calls
- Limit concurrency to avoid overwhelming external services

### When to use it (and when not to)

[](#when-to-use-it-and-when-not-to)

✅ **Good fit:**

- Tasks are **independent** and don't share state
- Each task can run as a **separate PHP script or CLI command**
- You need **timeout protection** for unreliable tasks
- You want to **limit concurrency** (e.g., max 5 API calls at once)
- Tasks take **seconds to minutes** to complete

❌ **Consider alternatives for:**

- Tasks requiring **shared memory** or real-time inter-process communication → use [parallel](https://www.php.net/manual/en/book.parallel.php) extension
- **Web request handling** with high throughput → use a message queue (Redis, RabbitMQ, SQS)
- **Sub-second task spawning** at high frequency → process overhead becomes significant
- **Long-running daemon processes** → use Supervisor or systemd instead

---

Real-World Use Cases
--------------------

[](#real-world-use-cases)

### 1. Batch Data Import

[](#1-batch-data-import)

Import thousands of records by processing files in parallel:

```
$manager = new ProcessManager(executable: 'php', maxConcurrentProcesses: 5);

foreach (glob('/data/imports/*.csv') as $file) {
    $manager->addScript('import-worker.php', arguments: [$file], maxExecutionTime: 300);
}

$results = $manager->run();
echo "Imported " . count(array_filter($results, fn($r) => $r->wasSuccessful)) . " files\n";
```

### 2. Multi-API Data Collection

[](#2-multi-api-data-collection)

Fetch data from multiple APIs simultaneously:

```
$endpoints = ['users', 'orders', 'products', 'inventory', 'analytics'];

$manager = new ProcessManager(executable: 'php', maxConcurrentProcesses: 3);

foreach ($endpoints as $endpoint) {
    $manager->addScript('fetch-api.php', arguments: [$endpoint], maxExecutionTime: 60);
}

$results = $manager->run(); // All 5 endpoints fetched in ~2 batches instead of 5 sequential calls
```

### 3. Image/Video Processing Pipeline

[](#3-imagevideo-processing-pipeline)

Process media files in parallel using CLI tools:

```
$manager = new ProcessManager(executable: 'ffmpeg', maxConcurrentProcesses: 4);

foreach ($videoFiles as $video) {
    $manager->addScript("-i {$video} -vf scale=1280:720 output/{$video}", maxExecutionTime: 600);
}

$manager->run();
```

### 4. Database Migration Runner

[](#4-database-migration-runner)

Run independent migrations concurrently:

```
$manager = new ProcessManager(executable: 'php', maxConcurrentProcesses: 3);

$manager->addScripts([
    ['script' => 'migrate-users.php', 'maxExecutionTime' => 300],
    ['script' => 'migrate-orders.php', 'maxExecutionTime' => 600],
    ['script' => 'migrate-products.php', 'maxExecutionTime' => 300],
    ['script' => 'migrate-analytics.php', 'maxExecutionTime' => 900],
]);

$results = $manager->run();
```

### 5. Parallel Test Execution

[](#5-parallel-test-execution)

Run test suites faster:

```
$manager = new ProcessManager(executable: 'php', maxConcurrentProcesses: 4);

foreach (glob('tests/*Test.php') as $testFile) {
    $manager->addScript('vendor/bin/phpunit', arguments: [$testFile], maxExecutionTime: 120);
}

$results = $manager->run();
$failed = array_filter($results, fn($r) => !$r->wasSuccessful);

exit(count($failed) > 0 ? 1 : 0);
```

### 6. Multi-Server Deployment

[](#6-multi-server-deployment)

Deploy to multiple servers simultaneously:

```
$servers = ['web1.example.com', 'web2.example.com', 'web3.example.com'];

$manager = new ProcessManager(executable: 'ssh', maxConcurrentProcesses: 10);

foreach ($servers as $server) {
    $manager->addScript("{$server} 'cd /app && git pull && composer install'", maxExecutionTime: 120);
}

$results = $manager->run();
```

---

Features
--------

[](#features)

- 🚀 **Concurrent Execution** - Run multiple processes in parallel
- ⏱️ **Timeout Management** - Automatically kill processes that exceed time limits
- 📊 **Result Tracking** - Get detailed results for each process (exit codes, output, timing)
- 🎨 **Flexible Output** - Console, HTML, or custom output handlers
- 🔧 **Fluent API** - Chain configuration methods for clean setup
- 🏷️ **Fully Typed** - PHP 8.2+ with strict typing and readonly classes

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- `proc_open` function enabled

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require dalehurley/process-manager
```

### Manual Installation

[](#manual-installation)

Clone the repository and include the autoloader:

```
git clone https://github.com/dalehurley/PHP-Process-Manager.git
cd PHP-Process-Manager
composer install
```

Quick Start
-----------

[](#quick-start)

```
