sqonk/phext-detach
Composer 安装命令:
composer require sqonk/phext-detach
包简介
Detach is a library for running tasks inside of a PHP script in parallel using forked processes.
README 文档
README
Detach is a library for running tasks inside of a PHP script in parallel using forked processes. It clones a seperate process (based on the parent) and executes the requested callback.
It is light weight and relies on little more than the PCNTL and APCu PHP extensions plus a minor set of composer packages.
Detach is also minimalist in nature with just a small set of functions and classes to memorise. There is no event system and no architecture to learn, allowing it to fit easily within an existing code structure.
See the examples for a quick start guide.
While the spawned tasks have the ability to return data back to the parent there is also the option of using Channels, a loose implementation of channels from the Go language, which provide a simple way of allowing independent processes to send and receive data between one another.
Channels can also be used as logic gates for controlling the execution of various tasks by forcing them to wait for incoming data where required.
Install
Via Composer
$ composer require sqonk/phext-detach
Updating past V1.0
Release 1.1 changes the value returned from both a Channel and a BufferedChannel when they are closed. Previously they would return NULL, now they return the constant CHAN_CLOSED. This was done in order to clearly differentiate between null values intentionally inserted into a channel and channel closure.
Code written previously akin to the following:
while ($value = $chan->get()) { // process value. }
Should now be written as follows:
while (($value = $chan->get()) !== CHAN_CLOSED) { // process value. }
Alternatively, for the purposes of maintaining simpler syntax, you can now use a generator:
// function call.. foreach ($chan->incoming() as $value) { // process value. } // or directly passing the object as the iterator.. foreach ($chan as $value) { // process value. }
Updating from V0.4
Release 0.5+ adjusts the way Dispatcher::map() works so that it automatically builds and starts the TaskMap, returning the result of ->start() on the map object. Its parameters have also been expanded to accept the various TaskMap configuration options directly, in preparation for named parameters in PHP8.
Updating from V0.3
Release 0.4+ is a significant update from previous versions. It will break existing code that was built to use V0.3.
Most notably, the class that was formerly named Channel has been renamed to BufferedChannel and a new Channel class has taken its place. You can read more about both classes below.
Also, later in development, the file-based data storage for transferring data between tasks was switched to APCu, now requiring the extension in addition to PCNTL.
Documentation
API Reference now available.
Examples
Skim through the example code for a quick start guide on the basic concepts.
Credits
Theo Howell
Please see original concept of pnctl Threading by Tudor Barbu @ motanelu/php-thread
License
The MIT License (MIT). Please see License File for more information.
sqonk/phext-detach 适用场景与选型建议
sqonk/phext-detach 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 90 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parallel」 「multitasking」 「pcntl」 「concurrent」 「concurrency」 「multi-tasking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sqonk/phext-detach 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sqonk/phext-detach 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sqonk/phext-detach 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The public Recoil API, for library and application developers.
Integrate Recoil with ReactPHP.
Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.
Asynchronous coroutines for PHP 7.
Provides a better API to work with processes on Unix-like systems
Console implementation.
统计信息
- 总下载量: 90
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-02