WordPress.org

Make WordPress Core

Ticket #44458: memory-plugin-1.php

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

Test plugin that uses a lot of memory

Line 
1<?php
2/*
3Plugin Name: A plugin that uses a lot of memory while loading
4Plugin URI: http://localhost/
5Description: Uses a lot of memory while the plugin loads
6Author: mattr
7Version: 1.0
8*/
9
10define('WASTE_MEMORY_MB', 119);
11//define('WASTE_MEMORY_MB', 55);
12
13
14function waste_memory() { 
15        error_log('Current memory usage: ' . memory_get_usage());
16        error_log('  Allocating memory: ' . WASTE_MEMORY_MB . 'MB');
17
18        // 8 bytes x 128 x 1024 = 1 MB, multiplied by the constant
19        $_SERVER['wasted_memory'] = str_repeat('12345678', 128 * 1024 * WASTE_MEMORY_MB);
20
21        error_log('  Memory after allocation: ' . memory_get_usage());
22}
23
24// Use up some memory now, while loading plugins
25waste_memory();