Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Add Feature: monitoring values (e.g. memory) onEachChunk #19

Open
versusbassz opened this issue Apr 6, 2022 · 1 comment
Open

Add Feature: monitoring values (e.g. memory) onEachChunk #19

versusbassz opened this issue Apr 6, 2022 · 1 comment
Assignees

Comments

@versusbassz
Copy link
Owner

the prototype:

$iterator->add_feature( new class extends Feature implements AfterEachChunk{
			public function afterEachChunk() {

				$memory = number_format( (float) memory_get_usage(), 0, '.', ' ' );
				dump( $memory );
			}
		} );
@versusbassz
Copy link
Owner Author

another sample:

$iterator->add_feature( new class extends Feature implements OnStart, AfterEachChunk, OnFinish {
	protected int $chunk_time;
	protected int $start_time;

	public function OnStart() {
		$this->chunk_time = $this->start_time = time();
	}

	public function afterEachChunk() {
		$current_time = time();
		echo ( $current_time - $this->chunk_time ) . ' sec' . PHP_EOL;
		$this->chunk_time = $current_time;
	}

	public function onFinish() {
		echo 'Total time: ' . (string) ( time() - $this->start_time ) . ' sec' . PHP_EOL;
	}
} );

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant