WordPress.org

Make WordPress Core

Ticket #44458: memory-plugin-2.php

File memory-plugin-2.php, 737 bytes (added by WFMattR, 14 months ago)

Test plugin that uses a little memory, after plugins have loaded

Line 
1<?php
2/*
3Plugin Name: A plugin that uses little memory using a hook
4Plugin URI: http://localhost/
5Description: Uses a little memory during a hook's execution
6Author: mattr
7Version: 1.0
8*/
9
10define('HOOKED_WASTE_MEMORY_MB', 5);
11
12
13function waste_memory_hooked() { 
14        error_log('  (in hook) Current memory usage: ' . memory_get_usage());
15        error_log('    (in hook) Allocating memory: ' . HOOKED_WASTE_MEMORY_MB . 'MB');
16
17        // 8 bytes x 128 x 1024 = 1 MB, multiplied by the constant
18        $_SERVER['wasted_memory_2'] = str_repeat('12345678', 128 * 1024 * HOOKED_WASTE_MEMORY_MB);
19
20        error_log('    (in hook) Memory after allocation: ' . memory_get_usage());
21}
22
23// Use up some memory later, using a hook
24add_action('wp_loaded', 'waste_memory_hooked');