HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/local/wp/vendor/wp-cli/php-cli-tools/examples/common.php
<?php

if (php_sapi_name() != 'cli') {
	die('Must run from command line');
}

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
ini_set('log_errors', 0);
ini_set('html_errors', 0);

foreach(array(__DIR__ . '/../vendor', __DIR__ . '/../../../../vendor') as $vendorDir) {
	if(is_dir($vendorDir)) {
		require_once $vendorDir . '/autoload.php';
		break;
	}
}

function test_notify(cli\Notify $notify, $cycle = 1000000, $sleep = null) {
	for ($i = 0; $i < $cycle; $i++) {
		$notify->tick();
		if ($sleep) usleep($sleep);
	}
	$notify->finish();
}

function test_notify_msg(cli\Notify $notify, $cycle = 1000000, $sleep = null) {
	$notify->display();
	for ($i = 0; $i < $cycle; $i++) {
		// Sleep before tick to simulate time-intensive work and give time
		// for the initial message to display before it is changed
		if ($sleep) usleep($sleep);
		$msg = sprintf('  Finished step %d', $i + 1);
		$notify->tick(1, $msg);
	}
	$notify->finish();
}