承接 console-helpers/process-iterator 相关项目开发

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

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

console-helpers/process-iterator

Composer 安装命令:

composer require console-helpers/process-iterator

包简介

Sequential way to run Symfony Processes in parallel

README 文档

README

CI codecov Scrutinizer Code Quality

Latest Stable Version Total Downloads License

ProcessIterator is a PHP class, that allows writing sequential code to handle processes, that run in parallel.

This is a modified version of the FutureIterator class from Phabricator project adapted to with with Symfony Process component.

Installation

  • execute this command to add dependencies: php composer.phar require console-helpers/process-iterator:dev-master

Usage

IMPORTANT: Keys are preserved, but the order of elements is not. Iteration is done over the processes in the order they are executed, so the fastest process is the one you'll get first. This allows you to start doing followup processing as soon as possible.

<?php

use ConsoleHelpers\ProcessIterator\ProcessIterator;
use Symfony\Component\Process\Process;

$processes = array(
	'a.txt' => new Process('wc -c a.txt'),
	'b.txt' => new Process('wc -c b.txt'),
	'c.txt' => new Process('wc -c c.txt'),
);


// All of the processes will be started at once, when "foreach" line is executed.
$process_iterator = new ProcessIterator($processes);

foreach ($process_iterator as $key => $process) {
	$stderr = $process->getErrorOutput();
	$stdout = $process->getOutput();
	do_some_processing($stdout);
}


// Will only run 2 processes in parallel at a time.
$process_iterator = new ProcessIterator($processes);
$process_iterator->limit(2);

foreach ($process_iterator as $key => $process) {
	$stderr = $process->getErrorOutput();
	$stdout = $process->getOutput();
	do_some_processing($stdout);
}


// Will run all processes in parallel. The $processes array can be inspected later 
// to see execution results.
$process_iterator = new ProcessIterator($processes);
$process_iterator->runAll();


// Allows to add more processes in real time as they are processed.
$process_iterator = new ProcessIterator($processes);

foreach ($process_iterator as $key => $process) {
	$stderr = $process->getErrorOutput();
	$stdout = $process->getOutput();
	do_some_processing($stdout);

	if ( $key === 'b.txt' ) {
		$process_iterator->addProcess(
			new Process('wc -c d.txt'),
			'd.txt'
		);
	}
}


// Show "processing ..." message at if no process was finished executing after 
// given time has passed. This can happen several times as well.
$process_iterator = new ProcessIterator($processes);
$process_iterator->setUpdateInterval(1);

foreach ($process_iterator as $key => $process) {
	if ($process === null) {
		echo "Still working...\n";
	}
	else {
		$stderr = $process->getErrorOutput();
		$stdout = $process->getOutput();
		do_some_processing($stdout);
	}
}


// Safe process exception detection. When exception happens during process 
// execution it's recorded and that process is immediately yielded. Then
// the $process_iterator->getProcessException() method can be used to 
// handle it gracefully (e.g. re-add back to queue).
$process_iterator = new ProcessIterator($processes);

foreach ($process_iterator as $key => $process) {
	$process_exception = $process_iterator->getException();

	if ( $process_exception instanceof ProcessTimedOutException ) {
		echo "The $key process timed out.\n";
	}
	elseif ( $process_exception instanceof ProcessFailedException ) {
		echo "The $key process has failed.\n";
	}
	else {
		$stderr = $process->getErrorOutput();
		$stdout = $process->getOutput();
		do_some_processing($stdout);
	}
}

Contributing

See CONTRIBUTING file.

License

ProcessIterator is released under the BSD-3-Clause License. See the bundled LICENSE file for details.

console-helpers/process-iterator 适用场景与选型建议

console-helpers/process-iterator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.93k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 console-helpers/process-iterator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 10.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2016-03-05