petenelson/progress-estimator

PHP 类,用于估计一组任务的剩余时间

1.0.0 2019-04-14 15:25 UTC

This package is auto-updated.

Last update: 2024-09-25 19:42:29 UTC


README

PHP 库,用于估计一组任务的剩余时间。

Build Status Percentage of issues still open

当处理一个耗时较长的项目批处理时,可以使用此库来计算并显示剩余的估计时间。

Processing 12 items
[1/12]: Bacon ipsum dolor amet (0:35)
[2/12]: Cow porchetta labore shankle (0:33)
[3/12]: Filet mignon porchetta eiusmod tri-tip (0:28)
[4/12]: Venison aliqua, ad brisket pariatur (0:22)
[5/12]: Turkey reprehenderit picanha (0:18)
[6/12]: Turducken fatback ground round (0:16)
[7/12]: Strip steak leberkas laborum (0:12)
[8/12]: Pork belly excepteur buffalo (0:09)
[9/12]: ham chuck ipsum nostrud jerky (0:07)
[10/12]: Rump shank jalapeno (0:05)
[11/12]: Pancetta chicken do spare ribs, (0:02)
[12/12]: Meatball tenderloin picanha (0:00)

安装和使用

此包可以通过 composer 安装。

composer require petenelson/progress-estimator

下面有一些示例代码,请确保查看 examples.php 文件 以获取工作实现。

require_once __DIR__ . '/vendor/autoload.php';

$items = get_large_list_of_items();
$count = count($items);

// Create the progress estimator.
$estimator = new \PHPEstimator\ProgressEstimator($count);

// Loop through the list of items to process.
for ($i=0; $i < $count; $i++) {

	// Perform some work on each item.
	some_long_running_process_here($items[$i]);

	// Increments the counter and saves the execution time of that item.
	$estimator->tick();

	// Display the current item processed and estimated time remaining.
	$output = sprintf(
		'Processed: %1$s (%2$s)' . PHP_EOL,
		$i,
		$estimator->formatTime($estimator->timeLeft())
	);

	echo $output;
}