parallite / parallite-php
Standalone PHP client for Parallite - Execute PHP closures in true parallel
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/parallite/parallite-php
Requires
- php: ^8.3
- ext-sockets: *
- ext-zip: *
- opis/closure: ^4.3
- rybakit/msgpack: ^0.9.1
Requires (Dev)
- laravel/pint: ^1.25
- pestphp/pest: ^4.0
- phpstan/phpstan: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
README
Parallite {PHP Client}
Execute PHP closures in true parallel - A standalone PHP client for Parallite, enabling real parallel execution of PHP code without the limitations of traditional PHP concurrency.
โจ Features
- ๐ True Parallel Execution - Execute multiple PHP closures simultaneously
- ๐ฏ Simple async/await API - Familiar Promise-like interface
- ๐ Promise Chaining - Chainable
then(),catch(), andfinally()methods - ๐ Cross-platform - Works on Windows, Linux and macOS
- โฏ๏ธ๏ธ Automatic Daemon Management - Optional auto-start/stop of Parallite daemon
- โก Binary MessagePack Transport - Ultra-fast daemon communication (2-5x faster than JSON)
๐ Requirements
- PHP 8.3+
- ext-sockets
- ext-zip
- rybakit/msgpack
- opis/closure
โ ๏ธ Important Notice:
Passing closures that capture
$thiswill cause opis/closure to serialize the entire object instance. This often includes nonโserializable dependencies (e.g., PDO, CurlHandle, resource, sockets, Laravel Models, Collections, etc) and may lead to errors.๐ Please review the Troubleshooting page for guidance on how to avoid this issue and know more.
๐ฆ Installation
composer require parallite/parallite-php
Add the install/update scripts to your composer.json:
{
"scripts": {
"post-install-cmd": [
"@php vendor/parallite/parallite-php/bin/parallite-install"
],
"post-update-cmd": [
"@php vendor/parallite/parallite-php/bin/parallite-update"
]
}
}
See more about these scripts: Installation Guide.
After adding the scripts, run (to download Parallite binary):
composer install
# or update
composer update
๐ Quick Start
<?php require 'vendor/autoload.php'; // Basic usage - no imports needed! $result = await(async(fn() => 'Hello World')); echo $result; // Hello World // Parallel execution $p1 = async(fn() => sleep(1) && 'Task 1'); $p2 = async(fn() => sleep(1) && 'Task 2'); $p3 = async(fn() => sleep(1) && 'Task 3'); $results = await([$p1, $p2, $p3]); // Total time: ~1s (parallel) instead of 3s (sequential) // Promise chaining $result = await( async(fn() => 1 + 2) ->then(fn($n) => $n * 2) ->then(fn($n) => $n + 5) ); echo $result; // 11 // Error handling $result = await( async(function () { throw new Exception('Oops!'); })->catch(fn($e) => 'Caught: ' . $e->getMessage()) ); echo $result; // Caught: Task failed: Oops!
That's it! The daemon is automatically managed - no manual setup required!
๐ Documentation
- Quick Start Guide - Get up and running in minutes
- Installation - Detailed installation instructions
- Configuration - Customize daemon behavior and PHP includes
- API Reference - Complete API documentation
- Complex Data Handling - How to handle complex data structures
- Troubleshooting - Common issues and solutions
- Examples - Real-world usage examples
โก Performance
Parallite provides significant speedup for I/O-bound and CPU-bound tasks:
| Tasks | Sequential | Parallel | Speedup |
|---|---|---|---|
| 3 ร 1s | 3.0s | ~1.0s | 3.0x |
| 5 ร 2s | 10.0s | ~2.0s | 5.0x |
| 10 ร 1s | 10.0s | ~1.0s | 10.0x |
Parallelism is beneficial when:
โ
CPU-intensive operations (image processing, complex calculations)
โ
Independent I/O-bound operations (external API calls, multiple databases)
โ
Database with good concurrency (MongoDB, PostgreSQL, SQL Server, MySQL)
โ SQLite with concurrent writes
โ Operations are already very fast
Example using the Filamentphp demo
Project with + 20 thousand orders, simulating several heavy calculations and with json transformation, as if it were for a heavy dashbaord (when I have time, I'll add this demo project to git):
โ With Parallite:
๐ซ Without Parallite:
The increase was approximately 321.4% in orders processed per second.
Real-World Example
// Fetch multiple APIs in parallel $promises = [ 'users' => async(fn() => file_get_contents('https://api.example.com/users')), 'posts' => async(fn() => file_get_contents('https://api.example.com/posts')), 'comments' => async(fn() => file_get_contents('https://api.example.com/comments')), ]; $data = await($promises); // 3x faster than sequential fetching!
Run the real-world test suite (uses data available at https://jsonplaceholder.typicode.com):
RUN_REAL_WORLD_TESTS=1 vendor/bin/pest tests/Feature/RealWorldDataProcessingTest.php --no-coverage
๐ Platform Support
| Platform | Status | Notes |
|---|---|---|
| Linux | โ Fully Supported | x86_64, ARM64 |
| macOS | โ Fully Supported | Intel, Apple Silicon |
| Windows | โ Fully Supported | x86_64, ARM64 |
๐ Troubleshooting
Having issues? Check the Troubleshooting Guide for solutions.
Quick tip:
- You can use
pd()insideasync()calls, it will throw an exception with the dump data. - Never capture
$thisin closures passed toasync(). Use static methods or extract primitives instead.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Credits
- Parallite Daemon: b7s/parallite
- Closure Serialization: opis/closure
- MessagePack: rybakit/msgpack
- Inspired by: Pokio
๐ฎ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with โค๏ธ by the Parallite community

