<?php
/*
Plugin Name: A plugin that uses little memory using a hook
Plugin URI: http://localhost/
Description: Uses a little memory during a hook's execution
Author: mattr
Version: 1.0
*/

define('HOOKED_WASTE_MEMORY_MB', 5);


function waste_memory_hooked() { 
	error_log('  (in hook) Current memory usage: ' . memory_get_usage());
	error_log('    (in hook) Allocating memory: ' . HOOKED_WASTE_MEMORY_MB . 'MB');

	// 8 bytes x 128 x 1024 = 1 MB, multiplied by the constant
	$_SERVER['wasted_memory_2'] = str_repeat('12345678', 128 * 1024 * HOOKED_WASTE_MEMORY_MB);

	error_log('    (in hook) Memory after allocation: ' . memory_get_usage());
}

// Use up some memory later, using a hook
add_action('wp_loaded', 'waste_memory_hooked');
