承接 parallite/parallite-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

parallite/parallite-php

Composer 安装命令:

composer require parallite/parallite-php

包简介

Execute PHP closures in true parallel using pcntl_fork — zero dependencies

README 文档

README

Parallite Logo

Parallite PHP

Latest Version PHP Version License

Execute PHP closures in true parallel — native pcntl_fork with zero dependencies, no daemon, no binary, no serialization.

Features

  • True Parallel Executionpcntl_fork runs closures in separate processes simultaneously
  • Zero Dependencies — only PHP 8.3+ with ext-pcntl and ext-posix (built-in)
  • No Daemon, No Binary — no external process to install, start, or manage
  • No Closure Serialization — forked processes inherit parent memory; closures run as-is
  • Simple async/await API — familiar Promise-like interface with global helpers
  • Promise Chaining — chainable then(), catch(), and finally() methods
  • Cross-platform — fork mode on Linux/macOS, automatic sequential fallback on Windows
  • Benchmark Mode — optional per-task metrics (execution time, memory, CPU)

Requirements

  • PHP 8.3+
  • ext-pcntl (Linux/macOS — built-in, enables fork mode)
  • ext-posix (Linux/macOS — built-in, enables fork mode)

Windows? Parallite works on Windows in sequential fallback mode (no pcntl_fork). Parallel execution requires a Unix-like OS.

Installation

composer require parallite/parallite-php

That's it. No binary to download, no daemon to start, no post-install scripts.

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: Oops!

Documentation

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:

with-parallite

🚫 Without Parallite:

with-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!

Platform Support

Platform Status Notes
Linux ✅ Fully Supported Fork mode (parallel)
macOS ✅ Fully Supported Fork mode (parallel)
Windows ⚠️ Sequential Mode No pcntl_fork — runs closures sequentially

Troubleshooting

Having issues? Check the Troubleshooting Guide for solutions.

Quick tip: Use pd() inside async() calls — it throws an exception with the dump data.

How It Works

Parallite uses pcntl_fork() to create child processes that inherit the parent's entire memory space. This means:

  1. No closure serialization — closures run directly in the forked process
  2. No external daemon — each async() call forks immediately
  3. No startup overhead — fork is near-instantaneous (~0.1ms)
  4. Simple IPC — child writes result to a temp file, parent reads it on await()

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

Support

Made with ❤️ by the Parallite community

parallite/parallite-php 适用场景与选型建议

parallite/parallite-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 185 次下载、GitHub Stars 达 6, 最近一次更新时间为 2025 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「fork」 「closure」 「async」 「parallel」 「pcntl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 parallite/parallite-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 parallite/parallite-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 parallite/parallite-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 185
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 33
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-16