1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: A plugin that uses little memory using a hook |
---|
4 | Plugin URI: http://localhost/ |
---|
5 | Description: Uses a little memory during a hook's execution |
---|
6 | Author: mattr |
---|
7 | Version: 1.0 |
---|
8 | */ |
---|
9 | |
---|
10 | define('HOOKED_WASTE_MEMORY_MB', 5); |
---|
11 | |
---|
12 | |
---|
13 | function 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 |
---|
24 | add_action('wp_loaded', 'waste_memory_hooked'); |
---|