jotaelesalinas/php-simple-mapreduce
Composer 安装命令:
composer require jotaelesalinas/php-simple-mapreduce
包简介
A simple in-memory map/reduce engine for PHP iterables, without workers or configuration.
关键字:
README 文档
README
[!IMPORTANT] This is a breaking v3 release.
Simple in-memory map/reduce for PHP iterables.
This library is for local data processing when you want a small, readable API and do not need distributed workers, external storage, or tuning knobs. It is the lighter counterpart to heavier MapReduce-style systems.
Why this exists
- Works with any
iterable, including arrays, generators, and custom iterators. - Keeps all work inside one PHP process.
- Exposes a small fluent API that is easy to test.
- Lets you observe progress without coupling to a logger.
Install
composer require jotaelesalinas/php-simple-mapreduce
Quickstart
<?php declare(strict_types=1); use JLSalinas\SimpleMapReduce\MapReduce; $result = MapReduce::create() ->input([1, 2, 3, 4, 5]) ->map(static fn (mixed $item): mixed => $item * 2) ->reduce(static fn (mixed $carry, mixed $item): mixed => ($carry ?? 0) + $item) ->run(); var_dump($result);
If you prefer a reusable callable, the same pipeline works with any callable that matches the expected signature: built-ins, named functions, static methods, closures, and invokable objects:
$doublerFn = static fn (mixed $item): mixed => $item * 2; final class Stats { public static function max(?int $carry, int $item): int { return $carry === null ? $item : max($carry, $item); } } $result = MapReduce::create() ->input([1, 2, 3, 4, 5]) ->map($doublerFn) ->reduce([Stats::class, 'max']) ->run();
Semantics
input()accepts one or moreiterablesources.- The pipeline runs in this order: input, input filter, mapper, group key, mapped filter, reducer.
filterInput()receives the raw input item and decides whether it enters the mapper.map()transforms each input item before reduction.groupBy()can group by array key, object property, or callback.filterMapped()receives the mapped item and, when grouping is enabled, the computed group key.reduce()receives the previous carry value and the mapped item.progress()receives the processed count, original item, and mapped item.output()can write reduced results to one or moreWriterinstances.
Fluent API
$result = MapReduce::create() ->input($items) ->filterInput($inputFilter) ->map($mapper) ->groupBy($groupBy) ->filterMapped($mappedFilter) ->reduce($reducer) ->progress($progressCallback) ->output($writer) ->run();
When to use this
- Use this library when you need a local, readable aggregation pipeline.
- Use a distributed engine when you need parallel workers or external storage.
- Use
php-data-streamswhen you need specialized streaming readers and writers for formats such as CSV, JSON, XML, or xlsx.
Examples
To run the examples locally from the repository root:
composer install php examples/pets.php php examples/insurance.php php examples/benchmark-big-dataset.php
Development
composer install
composer test
composer analyse
composer format
Updating from v2.x
If you are coming from v2.x, these are the main changes to review:
-
The namespace is now
JLSalinas\SimpleMapReduce. If your code still has imports like:use JLSalinas\MapReduce\MapReduce;
change them to:
use JLSalinas\SimpleMapReduce\MapReduce;
-
The public API has been modernized around a fluent pipeline. If your v2 code used setters or explicit configuration methods, replace them with the current chainable methods. For example, code that used
setInput(),setMapper(), andsetReducer()should now use:MapReduce::create() ->input($items) ->map($mapper) ->reduce($reducer) ->run();
-
If your code used
setPreFilter(),setPostFilter(), orsetGroupBy(), re-check the current method names and the execution order in Semantics. These callbacks still exist conceptually, but the surrounding pipeline is now organized differently. -
progress()andoutput()still exist, but you should re-test any code that depends on side effects, callback order, or the exact shape of the reduced output. -
If you are still installing the old package name, switch Composer to the new package:
composer remove jotaelesalinas/php-mapreduce composer require jotaelesalinas/php-simple-mapreduce
jotaelesalinas/php-simple-mapreduce 适用场景与选型建议
jotaelesalinas/php-simple-mapreduce 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 11, 最近一次更新时间为 2026 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「php」 「Simple」 「pipeline」 「aggregation」 「mapreduce」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jotaelesalinas/php-simple-mapreduce 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jotaelesalinas/php-simple-mapreduce 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jotaelesalinas/php-simple-mapreduce 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A simple library for make Lexer and Parsers to build a language
A simple library that allows transform any kind of data to native php data or whatever
A simple library that uses the hydration pattern to fill objects given different sources of data.
Micro Active Record library in PHP, support chain calls, events, and relations.
A simple content
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-09