sj-i/ffi-zts-parallel
Composer 安装命令:
composer require sj-i/ffi-zts-parallel
包简介
PHP-side wrapper around pecl/parallel for use through sj-i/ffi-zts (NTS host -> embedded ZTS interpreter -> real OS threads).
README 文档
README
NTS-hosted wrapper around
pecl/parallel
that runs through sj-i/ffi-zts.
Gives a plain non-thread-safe PHP CLI access to real OS-thread
parallelism via parallel\Runtime, without replacing the system
PHP build. See docs/DESIGN.md
in the core package for the full design.
Install
composer require sj-i/ffi-zts-parallel
Both sj-i/ffi-zts and sj-i/ffi-zts-parallel ship as Composer
plugins. On install, each downloads the pre-built binary matching
your host's PHP minor / CPU arch / libc:
vendor/sj-i/ffi-zts/bin/libphp.sovendor/sj-i/ffi-zts-parallel/bin/extensions/ffi-zts/parallel.so
Trusting the plugins
Composer 2.2+ asks you to trust a new plugin before running it.
In interactive shells you get a (y/N) prompt on first install.
In CI / non-interactive environments, whitelist both up front:
composer config allow-plugins.sj-i/ffi-zts true composer config allow-plugins.sj-i/ffi-zts-parallel true composer require sj-i/ffi-zts-parallel
Manual install / retry
If either plugin was skipped (--no-plugins, network outage, binary
not yet published for a new PHP minor), retry the binary fetch on
demand from the root project:
vendor/bin/ffi-zts install # fetches libphp.so # parallel.so is re-fetched on the next `composer update sj-i/ffi-zts-parallel`.
Usage
<?php require __DIR__ . '/vendor/autoload.php'; use SjI\FfiZts\Parallel\Parallel; Parallel::boot() ->runScript(__DIR__ . '/worker.php');
A minimal worker.php that fans out four parallel\Runtimes inside
the embed:
<?php $futures = []; for ($i = 0; $i < 4; $i++) { $rt = new parallel\Runtime(); $futures[] = $rt->run(function (int $id): array { $sum = 0; for ($j = 0; $j < 2_000_000; $j++) $sum += $j; return ['id' => $id, 'pid' => getmypid(), 'zts' => PHP_ZTS, 'sum' => $sum]; }, [$i]); } foreach ($futures as $f) { print_r($f->value()); }
All four workers report the same pid (same process) and
zts=true (running in the embedded ZTS interpreter).
opcache.preload (2.x / PHP 8.5)
PHP 8.5 links opcache statically into libphp.so, so
opcache.preload works under the embed out of the box and the
preloaded classes / functions propagate into every
parallel\Runtime worker thread:
Parallel::boot() ->withIniEntry('opcache.enable_cli', '1') ->withIniEntry('opcache.preload', __DIR__ . '/preload.php') ->withIniEntry('opcache.preload_user', get_current_user()) ->runScript(__DIR__ . '/worker.php');
See docs/PERFORMANCE.md
in the core repo for fork-vs-embed measurements.
Read-only / containerised environments
If the vendor directory is not writable at runtime (baked into a
container image, mounted read-only, etc.), Parallel::bootInMemory()
skips the disk cache and patches + loads parallel.so via
memfd_create(2):
Parallel::bootInMemory()->runScript('worker.php');
Versioning
Major tracks the host PHP minor:
ffi-zts-parallel1.x targets PHP 8.4 (host NTS / embedded ZTS).ffi-zts-parallel2.x targets PHP 8.5 and picks up upstream's static opcache for out-of-boxopcache.preload.
Minor / patch tracks upstream parallel releases plus wrapper
fixes; bumping just the parallel version is
composer update sj-i/ffi-zts-parallel.
Requirements
- Linux x86_64 or aarch64, glibc 2.31+
- Host NTS PHP matching the major you install -- 1.x needs
PHP 8.4, 2.x needs PHP 8.5 -- with
ext-ffienabled - Composer 2.2+
macOS, Windows, and musl are out of scope for the currently supported major lines; see the design doc for why.
sj-i/ffi-zts-parallel 适用场景与选型建议
sj-i/ffi-zts-parallel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「threads」 「parallel」 「composer-plugin」 「zts」 「ffi-zts」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sj-i/ffi-zts-parallel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sj-i/ffi-zts-parallel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sj-i/ffi-zts-parallel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Sequential way to run Symfony Processes in parallel
Composer plugin for preserving custom paths and supporting nested packages
Composer plugin
This Bundle provides threaded comment functionality for Symfony applications
Generic PHP Threads library using only pure PHP
Asynchronous parallel Twitter client built on the Amp concurrency framework
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-20