Skip to content

Commit f4c4dcd

Browse files
committed
Relase 1.3.8
feat(debug): Added php-memory.php
1 parent b2bc8da commit f4c4dcd

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## Relase 1.3.8
3+
* feat(debug): Added php-memory.php
4+
5+
26
## Release 1.3.7
37
* feat(ultimo): Added ultimo-api-fix.php
48

README-snippets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
| Title | Type | Status | Description |
4747
| ----- | ---- | ------ | ----------- |
4848
| [log-hook-calls.php](./debug/log-hook-calls.php) | Plugin | :white_check_mark: | Log all hook calls to a file |
49+
| [PHP Memory Info](./debug/php-memory.php) | mu-plugin | :white_check_mark: | Adds a Tools -> PHP Memory page to display PHP ini and WordPress memory settings and current usage. |
4950
| [show-browser-cookies.php](./debug/show-browser-cookies.php) | snippet | :white_check_mark: | * Description Shows your browsers cookies |
5051
| [Application Logs](./debug/show-logs-admin.php) | Plugin | :white_check_mark: | Displays top 10 lines from a log file in the WordPress admin section. |
5152

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ The status field is used to indicate the current status of the snippet. This is
6060
| Title | Type | Status | Description |
6161
| ----- | ---- | ------ | ----------- |
6262
| [log-hook-calls.php](./debug/log-hook-calls.php) | Plugin | :white_check_mark: | Log all hook calls to a file |
63+
| [PHP Memory Info](./debug/php-memory.php) | mu-plugin | :white_check_mark: | Adds a Tools -> PHP Memory page to display PHP ini and WordPress memory settings and current usage. |
6364
| [show-browser-cookies.php](./debug/show-browser-cookies.php) | snippet | :white_check_mark: | * Description Shows your browsers cookies |
6465
| [Application Logs](./debug/show-logs-admin.php) | Plugin | :white_check_mark: | Displays top 10 lines from a log file in the WordPress admin section. |
6566

@@ -136,6 +137,10 @@ The status field is used to indicate the current status of the snippet. This is
136137
| [Failover Status Monitor](./wp-failover/wp-failover.php) | Plugin | :white_check_mark: | Monitors failover status and provides notifications. |
137138

138139
# Changelog
140+
## Relase 1.3.8
141+
* feat(debug): Added php-memory.php
142+
143+
139144
## Release 1.3.7
140145
* feat(ultimo): Added ultimo-api-fix.php
141146

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.7
1+
1.3.8

debug/php-memory.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Plugin Name: PHP Memory Info
4+
* Description: Adds a Tools -> PHP Memory page to display PHP ini and WordPress memory settings and current usage.
5+
* Version: 1.0
6+
* Author: ManagingWP
7+
* Author URI: https://github.com/managingwp/wordpress-code-snippets
8+
* Type: mu-plugin
9+
* Status: Complete
10+
*/
11+
12+
// Exit if accessed directly
13+
if ( ! defined( 'ABSPATH' ) ) {
14+
exit;
15+
}
16+
17+
// Hook into admin menu to add the Tools > PHP Memory page
18+
add_action( 'admin_menu', 'pm_add_php_memory_page' );
19+
20+
/**
21+
* Register the PHP Memory page under Tools
22+
*/
23+
function pm_add_php_memory_page() {
24+
add_management_page(
25+
'PHP Memory', // Page title
26+
'PHP Memory', // Menu title
27+
'manage_options', // Capability
28+
'php-memory-info', // Menu slug
29+
'pm_render_php_memory_page' // Callback to render the page
30+
);
31+
}
32+
33+
/**
34+
* Render the PHP Memory Info page
35+
*/
36+
function pm_render_php_memory_page() {
37+
// Check permissions
38+
if ( ! current_user_can( 'manage_options' ) ) {
39+
return;
40+
}
41+
42+
// PHP ini settings
43+
$ini_settings = array(
44+
'file_uploads' => ini_get( 'file_uploads' ),
45+
'upload_max_filesize' => ini_get( 'upload_max_filesize' ),
46+
'post_max_size' => ini_get( 'post_max_size' ),
47+
'memory_limit' => ini_get( 'memory_limit' ),
48+
'max_execution_time' => ini_get( 'max_execution_time' ),
49+
'max_input_time' => ini_get( 'max_input_time' ),
50+
);
51+
52+
// WordPress memory settings
53+
$wp_memory_limit = defined( 'WP_MEMORY_LIMIT' ) ? WP_MEMORY_LIMIT : 'Not defined';
54+
$wp_max_memory_limit = defined( 'WP_MAX_MEMORY_LIMIT' ) ? WP_MAX_MEMORY_LIMIT : 'Not defined';
55+
56+
// Current memory usage in MB
57+
$current_memory_usage = round( memory_get_usage() / 1024 / 1024, 2 );
58+
59+
// Output
60+
echo '<div class="wrap">';
61+
echo '<h1>PHP Memory Info</h1>';
62+
63+
echo '<h2>PHP ini settings for file uploads</h2>';
64+
echo '<table class="widefat fixed"><thead><tr><th>Setting</th><th>Value</th></tr></thead><tbody>';
65+
foreach ( $ini_settings as $key => $value ) {
66+
echo '<tr><td>' . esc_html( $key ) . '</td><td>' . esc_html( $value ) . '</td></tr>';
67+
}
68+
echo '</tbody></table>';
69+
70+
echo '<h2>WordPress Memory Settings</h2>';
71+
echo '<table class="widefat fixed"><thead><tr><th>Setting</th><th>Value</th></tr></thead><tbody>';
72+
echo '<tr><td>WP_MEMORY_LIMIT</td><td>' . esc_html( $wp_memory_limit ) . '</td></tr>';
73+
echo '<tr><td>WP_MAX_MEMORY_LIMIT</td><td>' . esc_html( $wp_max_memory_limit ) . '</td></tr>';
74+
echo '</tbody></table>';
75+
76+
echo '<h2>What these WordPress settings do</h2>';
77+
echo "<p><strong>WP_MEMORY_LIMIT:</strong> The max amount of PHP memory WordPress will try to use for front-end operations (themes, plugins, media processing). It's a soft target—it cannot exceed PHP's own memory_limit in php.ini.</p>";
78+
echo "<p><strong>WP_MAX_MEMORY_LIMIT:</strong> A higher memory ceiling for admin tasks: dashboard, cron jobs, updates, and other background processes. Again, bounded by PHP's own memory_limit in php.ini.</p>";
79+
80+
echo '<h2>Current memory usage</h2>';
81+
echo '<p>' . esc_html( $current_memory_usage ) . ' MB</p>';
82+
83+
echo '</div>';
84+
}

0 commit comments

Comments
 (0)