Automattic\WooCommerce\Internal\ProductFeed\Utils

MemoryManager::get_available_memorypublicWC 10.5.0

Get available memory as a percentage of the total memory limit.

Method of the class: MemoryManager{}

No Hooks.

Returns

Int. Available memory as a percentage of the total memory limit.

Usage

$MemoryManager = new MemoryManager();
$MemoryManager->get_available_memory(): int;

Changelog

Since 10.5.0 Introduced.

MemoryManager::get_available_memory() code WC 10.8.1

public function get_available_memory(): int {
	$memory_limit = wp_convert_hr_to_bytes( ini_get( 'memory_limit' ) );
	if ( 0 >= $memory_limit ) {
		// Some systems have "unlimited" memory.
		// We should treat that as if there is none left.
		return 0;
	}
	return (int) round( 100 - ( memory_get_usage( true ) / $memory_limit ) * 100 );
}