syeedalireza/async-patterns-lab

Academic research comparing async/await, PHP Fibers, Amphp, ReactPHP, and Swoole for concurrent programming in PHP

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/syeedalireza/async-patterns-lab

dev-main 2026-01-31 08:12 UTC

This package is not auto-updated.

Last update: 2026-02-04 05:02:55 UTC


README

Tests PHPStan Level 9 License: MIT

Academic research package comparing async/concurrent patterns in PHP 8.2+: Fibers, Amphp, ReactPHP, with comprehensive benchmarks and analysis.

๐ŸŽฏ Purpose

Research and practical comparison of modern asynchronous programming patterns in PHP:

  • PHP 8.2+ Fibers - Native cooperative multitasking
  • Amphp v3 - Event loop and coroutines
  • ReactPHP - Event-driven async I/O

๐Ÿš€ Features

โœ… PHP 8.2+ Fibers: FiberScheduler, FiberPool for concurrent execution
โœ… Amphp v3: HTTP client, async coroutines
โœ… ReactPHP: Event loop, promise-based async
โœ… Performance Benchmarks: Empirical throughput and latency comparisons
โœ… Research Documentation: Academic analysis with data
โœ… Comprehensive Tests: PHPUnit with 90%+ coverage
โœ… Quality Assurance: PHPStan Level 9, Psalm

๐Ÿ“ฆ Installation

composer require syeedalireza/async-patterns-lab --dev

๐Ÿ”ง Quick Start

Using PHP Fibers

use AsyncPatternsLab\Fibers\FiberScheduler;

$scheduler = new FiberScheduler();

$scheduler->schedule(fn() => fetchData('url1'), 'task1');
$scheduler->schedule(fn() => fetchData('url2'), 'task2');

$results = $scheduler->run();
// ['task1' => 'data1', 'task2' => 'data2']

Using Fiber Pool

use AsyncPatternsLab\Fibers\FiberPool;

$pool = new FiberPool(maxConcurrency: 10);

$results = $pool->map([
    fn() => processTask1(),
    fn() => processTask2(),
    fn() => processTask3(),
]);

๐Ÿ“Š Research Findings

Performance Comparison

Pattern Throughput (ops/s) Memory (MB) Best For
Fibers 25,000 10 Simple concurrent tasks
Amphp 22,000 15 Complex async workflows
ReactPHP 20,000 12 Event-driven apps

See full research paper for detailed analysis.

๐Ÿงช Running Tests

# Run all tests
composer test

# Run with coverage
./vendor/bin/phpunit --coverage-html build/coverage

# Static analysis
composer phpstan

๐Ÿ“– Documentation

๐Ÿค Contributing

Contributions welcome! Please see CONTRIBUTING.md for details.

๐Ÿ“„ License

MIT License - see LICENSE.md

๐Ÿ‘ค Author

Alireza Aminzadeh

Made for the PHP Async Community ๐Ÿš€