PluginProbe
WP-ServerInfo / 1.65
WP-ServerInfo v1.65
3.0.0 trunk 1.00 1.30 1.31 1.40 1.50 1.65 1.66 2.0.0
wp-serverinfo / wp-serverinfo.php

wp-serverinfo.php in WP-ServerInfo 1.65, at wp-serverinfo.php

612 lines 30.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP-ServerInfo
4 Plugin URI: https://lesterchan.net/portfolio/programming/php/
5 Description: Display your host's PHP, MYSQL & memcached (if installed) information on your WordPress dashboard.
6 Version: 1.65
7 Author: Lester 'GaMerZ' Chan
8 Author URI: https://lesterchan.net
9 Text Domain: wp-serverinfo
10 */
11
12
13 /*
14 Copyright 2018 Lester Chan (email : lesterchan@gmail.com)
15
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 */
30
31
32 ### Create Text Domain For Translations
33 add_action('init', 'serverinfo_textdomain');
34 function serverinfo_textdomain() {
35 load_plugin_textdomain( 'wp-serverinfo' );
36 }
37
38
39 ### Function: WP-ServerInfo Menu
40 add_action('admin_menu', 'serverinfo_menu');
41 function serverinfo_menu() {
42 if (function_exists('add_submenu_page')) {
43 add_submenu_page('index.php', __('WP-ServerInfo', 'wp-serverinfo'), __('WP-ServerInfo', 'wp-serverinfo'), 'add_users', 'wp-serverinfo/wp-serverinfo.php', 'display_serverinfo');
44 }
45 }
46
47
48 ### Function: Enqueue ServerInfo JavaScripts In WP-Admin
49 add_action('admin_enqueue_scripts', 'serverinfo_scripts_admin');
50 function serverinfo_scripts_admin($hook_suffix) {
51 $serverinfo_admin_pages = array('dashboard_page_wp-serverinfo/wp-serverinfo');
52 if(in_array($hook_suffix, $serverinfo_admin_pages)) {
53 wp_enqueue_script('wp-serverinfo', plugins_url('wp-serverinfo/serverinfo-js.js'), array('jquery'), '1.60', true);
54 }
55 }
56
57
58 ### Display WP-ServerInfo Admin Page
59 function display_serverinfo() {
60 get_generalinfo();
61 get_phpinfo();
62 get_mysqlinfo();
63 get_memcachedinfo();
64 }
65
66
67 ### Get General Information
68 function get_generalinfo() {
69 global $is_IIS;
70 if( is_rtl() ) : ?>
71 <style type="text/css">
72 #GeneralOverview table,
73 #GeneralOverview th,
74 #GeneralOverview td {
75 direction: ltr;
76 text-align: left;
77 }
78 #GeneralOverview h2 {
79 padding: 0.5em 0 0;
80 }
81 </style>
82 <?php endif;
83 ?>
84 <div class="wrap" id="GeneralOverview">
85 <h2><?php _e('General Overview','wp-serverinfo'); ?></h2>
86 <?php serverinfo_subnavi(); ?>
87 <br class="clear" />
88 <table class="widefat">
89 <thead>
90 <tr>
91 <th><?php _e('Variable Name', 'wp-serverinfo'); ?></th>
92 <th><?php _e('Value', 'wp-serverinfo'); ?></th>
93 <th><?php _e('Variable Name', 'wp-serverinfo'); ?></th>
94 <th><?php _e('Value', 'wp-serverinfo'); ?></th>
95 </tr>
96 </thead>
97 <tbody>
98 <tr>
99 <td><?php _e('OS', 'wp-serverinfo'); ?></td>
100 <td><?php echo PHP_OS; ?></td>
101 <td><?php _e('Database Data Disk Usage', 'wp-serverinfo'); ?></td>
102 <td><?php echo format_filesize(get_mysql_data_usage()); ?></td>
103 </tr>
104 <tr class="alternate">
105 <td><?php _e('Server', 'wp-serverinfo'); ?></td>
106 <td><?php echo $_SERVER["SERVER_SOFTWARE"]; ?></td>
107 <td><?php _e('Database Index Disk Usage', 'wp-serverinfo'); ?></td>
108 <td><?php echo format_filesize(get_mysql_index_usage()); ?></td>
109 </tr>
110 <tr>
111 <td>PHP</td>
112 <td>v<?php echo PHP_VERSION; ?></td>
113 <td><?php _e('MYSQL Maximum Packet Size', 'wp-serverinfo'); ?></td>
114 <td><?php echo format_filesize(get_mysql_max_allowed_packet()); ?></td>
115 </tr>
116 <tr class="alternate">
117 <td>MYSQL</td>
118 <td>v<?php echo get_mysql_version(); ?></td>
119 <td><?php _e('MYSQL Maximum No. Connection', 'wp-serverinfo'); ?></td>
120 <td><?php echo number_format_i18n(get_mysql_max_allowed_connections()); ?></td>
121 </tr>
122 <tr>
123 <td>GD</td>
124 <td><?php echo get_gd_version(); ?></td>
125 <td><?php _e( 'MYSQL Query Cache Size', 'wp-serverinfo' ); ?></td>
126 <td><?php echo format_filesize( get_mysql_query_cache_size() ); ?></td>
127 </tr>
128 <tr class="alternate">
129 <td><?php _e('Server Hostname', 'wp-serverinfo'); ?></td>
130 <td><?php echo $_SERVER['SERVER_NAME']; ?></td>
131 <td><?php _e('PHP Short Tag', 'wp-serverinfo'); ?></td>
132 <td><?php echo get_php_short_tag(); ?></td>
133 </tr>
134 <tr>
135 <td><?php _e('Server IP:Port','wp-serverinfo'); ?></td>
136 <td><?php echo ($is_IIS ? $_SERVER['LOCAL_ADDR'] : $_SERVER['SERVER_ADDR']); ?>:<?php echo $_SERVER['SERVER_PORT']; ?></td>
137 <td><?php _e('PHP Magic Quotes GPC', 'wp-serverinfo'); ?></td>
138 <td><?php echo get_php_magic_quotes_gpc(); ?></td>
139 </tr>
140 <tr class="alternate">
141 <td><?php _e('Server Document Root','wp-serverinfo'); ?></td>
142 <td><?php echo $_SERVER['DOCUMENT_ROOT']; ?></td>
143 <td><?php _e('PHP Memory Limit', 'wp-serverinfo'); ?></td>
144 <td><?php echo format_php_size(get_php_memory_limit()); ?></td>
145 </tr>
146 <tr>
147 <td><?php _e('Server Admin', 'wp-serverinfo'); ?></td>
148 <td><?php echo (isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN']: ''); ?></td>
149 <td><?php _e('PHP Max Upload Size', 'wp-serverinfo'); ?></td>
150 <td><?php echo format_php_size(get_php_upload_max()); ?></td>
151 </tr>
152 <tr class="alternate">
153 <td><?php _e('Server Load', 'wp-serverinfo'); ?></td>
154 <td><?php echo get_serverLoad(); ?></td>
155 <td><?php _e('PHP Max Post Size', 'wp-serverinfo'); ?></td>
156 <td><?php echo format_php_size(get_php_post_max()); ?></td>
157 </tr>
158 <tr>
159 <td><?php _e('Server Date/Time', 'wp-serverinfo'); ?></td>
160 <td><?php echo mysql2date(sprintf(__('%s @ %s', 'wp-postratings'), get_option('date_format'), get_option('time_format')), current_time('mysql')); ?></td>
161 <td><?php _e('PHP Max Script Execute Time', 'wp-serverinfo'); ?></td>
162 <td><?php echo get_php_max_execution(); ?>s</td>
163 </tr>
164 </tbody>
165 </table>
166 </div>
167 <?php
168 }
169
170
171 ### Get PHP Information
172 function get_phpinfo() {
173 if( ! class_exists( 'DOMDocument' ) ) {
174 echo '<div class="wrap" id="PHPinfo" style="display: none;">';
175 echo '<h2>PHP ' . phpversion() . '</h2>';
176 serverinfo_subnavi();
177 echo 'You need <a href="http://php.net/manual/en/class.domdocument.php" target="_blank">DOMDocument extension</a> to be enabled.';
178 echo '</div>';
179 } else {
180 ob_start();
181 phpinfo();
182 $phpinfo = ob_get_contents();
183 ob_end_clean();
184
185 // Use DOMDocument to parse phpinfo()
186 $html = new DOMDocument( '1.0', 'UTF-8' );
187 $html->loadHTML( $phpinfo );
188
189 // Style process
190 $tables = $html->getElementsByTagName( 'table' );
191 foreach( $tables as $table ) {
192 $table->setAttribute( 'class', 'widefat' );
193 }
194
195 // We only need the <body>
196 $xpath = new DOMXPath($html);
197 $body = $xpath->query('/html/body');
198
199 // Save HTML fragment
200 $phpinfo_html = $html->saveXml( $body->item( 0 ) );
201
202 echo '<div class="wrap" id="PHPinfo" style="display: none;">';
203 echo '<h2>PHP ' . phpversion() . '</h2>';
204 serverinfo_subnavi();
205 echo $phpinfo_html;
206 echo '</div>';
207 }
208 }
209
210
211 ### Get MYSQL Information
212 function get_mysqlinfo() {
213 global $wpdb;
214 $sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
215 $mysqlinfo = $wpdb->get_results("SHOW VARIABLES");
216 if( is_rtl() ) : ?>
217 <style type="text/css">
218 #MYSQLinfo,
219 #MYSQLinfo table,
220 #MYSQLinfo th,
221 #MYSQLinfo td {
222 direction: ltr;
223 text-align: left;
224 }
225 #MYSQLinfo h2 {
226 padding: 0.5em 0 0;
227 }
228 </style>
229 <?php endif;
230 echo '<div class="wrap" id="MYSQLinfo" style="display: none;">'."\n";
231 echo "<h2>MYSQL $sqlversion</h2>\n";
232 serverinfo_subnavi();
233 if($mysqlinfo) {
234 echo '<br class="clear" />'."\n";
235 echo '<table class="widefat" dir="ltr">'."\n";
236 echo '<thead><tr><th>'.__('Variable Name', 'wp-serverinfo').'</th><th>'.__('Value', 'wp-serverinfo').'</th></tr></thead><tbody>'."\n";
237 foreach($mysqlinfo as $info) {
238 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>'.$info->Variable_name.'</td><td>'.htmlspecialchars($info->Value).'</td></tr>'."\n";
239 }
240 echo '</tbody></table>'."\n";
241 }
242 echo '</div>'."\n";
243 }
244
245
246 ### Get memcached Information (Description from https://boxpanel.blueboxgrp.com/public/the_vault/index.php/memcached_Tips)
247 function get_memcachedinfo() {
248 echo '<div class="wrap" id="memcachedinfo" style="display: none;">'."\n";
249 if(class_exists('Memcache')) {
250 $memcached_obj = new Memcache;
251 $memcached_obj->addServer('localhost', 11211);
252 $memcachedinfo = $memcached_obj->getStats();
253 if( is_rtl() ) : ?>
254 <style type="text/css">
255 #memcachedinfo,
256 #memcachedinfo table,
257 #memcachedinfo th,
258 #memcachedinfo td {
259 direction: ltr;
260 text-align: left;
261 }
262 #memcachedinfo h2 {
263 padding: 0.5em 0 0;
264 }
265 </style>
266 <?php endif;
267 echo "<h2>memcached {$memcachedinfo['version']}</h2>\n";
268 serverinfo_subnavi();
269 if($memcachedinfo) {
270 $cache_hit= ( $memcachedinfo['cmd_get'] > 0 ? ( ( $memcachedinfo['get_hits'] / $memcachedinfo['cmd_get'] ) * 100 ) : 0 );
271 $cache_hit = round($cache_hit, 2);
272 $cache_miss = 100 - $cache_hit;
273
274 $usage = round((($memcachedinfo['bytes']/$memcachedinfo['limit_maxbytes']) * 100), 2);
275 $uptime = number_format_i18n(($memcachedinfo['uptime']/60/60/24));
276
277 echo '<br class="clear" />'."\n";
278 echo '<table class="widefat" dir="ltr">'."\n";
279 echo '<thead><tr><th>'.__('Variable Name', 'wp-serverinfo').'</th><th>'.__('Value', 'wp-serverinfo').'</th><th>'.__('Description', 'wp-serverinfo').'</th></tr></thead><tbody>'."\n";
280 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>pid</td><td>'.$memcachedinfo['pid'].'</td><td>'.__('Process ID', 'wp-serverinfo').'</td></tr>'."\n";
281 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>uptime</td><td>'.$uptime.'</td><td>'.__('Number of days since the process was started', 'wp-serverinfo').'</td></tr>'."\n";
282 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>version</td><td>'.$memcachedinfo['version'].'</td><td>'.__('memcached version', 'wp-serverinfo').'</td></tr>'."\n";
283 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>rusage_user</td><td>'.$memcachedinfo['rusage_user'].'</td><td>'.__('Seconds the cpu has devoted to the process as the user', 'wp-serverinfo').'</td></tr>'."\n";
284 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>rusage_system</td><td>'.$memcachedinfo['rusage_system'].'</td><td>'.__('Seconds the cpu has devoted to the process as the system', 'wp-serverinfo').'</td></tr>'."\n";
285 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>curr_items</td><td>'.number_format_i18n($memcachedinfo['curr_items']).'</td><td>'.__('Total number of items currently in memcached', 'wp-serverinfo').'</td></tr>'."\n";
286 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>total_items</td><td>'.number_format_i18n($memcachedinfo['total_items']).'</td><td>'.__('Total number of items that have passed through memcached', 'wp-serverinfo').'</td></tr>'."\n";
287 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>bytes</td><td>'.format_filesize($memcachedinfo['bytes']).' ('.$usage.'%)</td><td>'.__('Memory size currently used by curr_items', 'wp-serverinfo').'</td></tr>'."\n";
288 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>limit_maxbytes</td><td>'.format_filesize($memcachedinfo['limit_maxbytes']).'</td><td>'.__('Maximum memory size allocated to memcached', 'wp-serverinfo').'</td></tr>'."\n";
289 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>curr_connections</td><td>'.number_format_i18n($memcachedinfo['curr_connections']).'</td><td>'.__('Total number of open connections to memcached', 'wp-serverinfo').'</td></tr>'."\n";
290 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>total_connections</td><td>'.number_format_i18n($memcachedinfo['total_connections']).'</td><td>'.__('Total number of connections opened since memcached started running', 'wp-serverinfo').'</td></tr>'."\n";
291 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>connection_structures</td><td>'.number_format_i18n($memcachedinfo['connection_structures']).'</td><td>'.__('Number of connection structures allocated by the server', 'wp-serverinfo').'</td></tr>'."\n";
292 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cmd_get</td><td>'.number_format_i18n($memcachedinfo['cmd_get']).'</td><td>'.__('Total GET commands issued to the server', 'wp-serverinfo').'</td></tr>'."\n";
293 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cmd_set</td><td>'.number_format_i18n($memcachedinfo['cmd_set']).'</td><td>'.__('Total SET commands issued to the server', 'wp-serverinfo').'</td></tr>'."\n";
294 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cmd_flush</td><td>'.number_format_i18n($memcachedinfo['cmd_flush']).'</td><td>'.__('Total FLUSH commands issued to the server', 'wp-serverinfo').'</td></tr>'."\n";
295 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>get_hits</td><td>'.number_format_i18n($memcachedinfo['get_hits']).' ('.$cache_hit.'%)</td><td>'.__('Total number of times a GET command was able to retrieve and return data', 'wp-serverinfo').'</td></tr>'."\n";
296 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>get_misses</td><td>'.number_format_i18n($memcachedinfo['get_misses']).' ('.$cache_miss.'%)</td><td>'.__('Total number of times a GET command was unable to retrieve and return data', 'wp-serverinfo').'</td></tr>'."\n";
297 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>delete_hits</td><td>'.number_format_i18n($memcachedinfo['delete_hits']).'</td><td>'.__('Total number of times a DELETE command was able to delete data', 'wp-serverinfo').'</td></tr>'."\n";
298 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>delete_misses</td><td>'.number_format_i18n($memcachedinfo['delete_misses']).'</td><td>'.__('Total number of times a DELETE command was unable to delete data', 'wp-serverinfo').'</td></tr>'."\n";
299 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>incr_hits</td><td>'.number_format_i18n($memcachedinfo['incr_hits']).'</td><td>'.__('Total number of times a INCR command was able to increment a value', 'wp-serverinfo').'</td></tr>'."\n";
300 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>incr_misses</td><td>'.number_format_i18n($memcachedinfo['incr_misses']).'</td><td>'.__('Total number of times a INCR command was unable to increment a value', 'wp-serverinfo').'</td></tr>'."\n";
301 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>decr_hits</td><td>'.number_format_i18n($memcachedinfo['decr_hits']).'</td><td>'.__('Total number of times a DECR command was able to decrement a value', 'wp-serverinfo').'</td></tr>'."\n";
302 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>decr_misses</td><td>'.number_format_i18n($memcachedinfo['decr_misses']).'</td><td>'.__('Total number of times a DECR command was unable to decrement a value', 'wp-serverinfo').'</td></tr>'."\n";
303 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cas_hits</td><td>'.number_format_i18n($memcachedinfo['cas_hits']).'</td><td>'.__('Total number of times a CAS command was able to compare and swap data', 'wp-serverinfo').'</td></tr>'."\n";
304 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cas_misses</td><td>'.number_format_i18n($memcachedinfo['cas_misses']).'</td><td>'.__('Total number of times a CAS command was unable to compare and swap data', 'wp-serverinfo').'</td></tr>'."\n";
305 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>cas_badval</td><td>'.number_format_i18n($memcachedinfo['cas_badval']).'</td><td>'.__('N/A', 'wp-serverinfo').'</td></tr>'."\n";
306 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>bytes_read</td><td>'.format_filesize($memcachedinfo['bytes_read']).'</td><td>'.__('Total number of bytes input into the server', 'wp-serverinfo').'</td></tr>'."\n";
307 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>bytes_written</td><td>'.format_filesize($memcachedinfo['bytes_written']).'</td><td>'.__('Total number of bytes written by the server', 'wp-serverinfo').'</td></tr>'."\n";
308 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>evictions</td><td>'.number_format_i18n($memcachedinfo['evictions']).'</td><td>'.__('Number of valid items removed from cache to free memory for new items', 'wp-serverinfo').'</td></tr>'."\n";
309 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>reclaimed</td><td>'.number_format_i18n($memcachedinfo['reclaimed']).'</td><td>'.__('Number of items reclaimed', 'wp-serverinfo').'</td></tr>'."\n";
310 echo '</tbody></table>'."\n";
311 }
312 }
313 echo '</div>'."\n";
314 }
315
316
317 ### WP-Server Sub Navigation
318 function serverinfo_subnavi($display = true) {
319 $output = '<p style="text-align: center">';
320 $output .= '<a href="#DisplayGeneral" onclick="toggle_general(); return false;">'.__('Display General Overview', 'wp-serverinfo').'</a>';
321 $output .= ' - <a href="#DisplayPHP" onclick="toggle_php(); return false;">'.__('Display PHP Information', 'wp-serverinfo').'</a>';
322 $output .= ' - <a href="#DisplayMYSQL" onclick="toggle_mysql(); return false;">'.__('Display MYSQL Information', 'wp-serverinfo').'</a>';
323 if(class_exists('Memcache')) {
324 $output .= ' - <a href="#Displaymemcached" onclick="toggle_memcached(); return false;">'.__('Display memcached Information', 'wp-serverinfo').'</a>';
325 }
326 $output .= '</p>';
327 if($display) {
328 echo $output;
329 } else {
330 return $output;
331 }
332 }
333
334
335 ### Function: Format Bytes Into TiB/GiB/MiB/KiB/Bytes
336 if(!function_exists('format_filesize')) {
337 function format_filesize($rawSize) {
338 if($rawSize / 1099511627776 > 1) {
339 return number_format_i18n($rawSize/1099511627776, 1).' '.__('TiB', 'wp-serverinfo');
340 } elseif($rawSize / 1073741824 > 1) {
341 return number_format_i18n($rawSize/1073741824, 1).' '.__('GiB', 'wp-serverinfo');
342 } elseif($rawSize / 1048576 > 1) {
343 return number_format_i18n($rawSize/1048576, 1).' '.__('MiB', 'wp-serverinfo');
344 } elseif($rawSize / 1024 > 1) {
345 return number_format_i18n($rawSize/1024, 1).' '.__('KiB', 'wp-serverinfo');
346 } elseif($rawSize > 1) {
347 return number_format_i18n($rawSize, 0).' '.__('bytes', 'wp-serverinfo');
348 } else {
349 return __('unknown', 'wp-serverinfo');
350 }
351 }
352 }
353
354 ### Function: Convert PHP Size Format to Localized
355 function format_php_size($size) {
356 if (!is_numeric($size)) {
357 if (strpos($size, 'M') !== false) {
358 $size = intval($size)*1024*1024;
359 } elseif (strpos($size, 'K') !== false) {
360 $size = intval($size)*1024;
361 } elseif (strpos($size, 'G') !== false) {
362 $size = intval($size)*1024*1024*1024;
363 }
364 }
365 return is_numeric($size) ? format_filesize($size) : $size;
366 }
367
368 ### Function: Get PHP Short Tag
369 if(!function_exists('get_php_short_tag')) {
370 function get_php_short_tag() {
371 if(ini_get('short_open_tag')) {
372 $short_tag = __('On', 'wp-serverinfo');
373 } else {
374 $short_tag = __('Off', 'wp-serverinfo');
375 }
376 return $short_tag;
377 }
378 }
379
380
381 ### Function: Get PHP Magic Quotes GPC
382 if(!function_exists('get_php_magic_quotes_gpc')) {
383 function get_php_magic_quotes_gpc() {
384 if(get_magic_quotes_gpc()) {
385 $magic_quotes_gpc = __('On', 'wp-serverinfo');
386 } else {
387 $magic_quotes_gpc = __('Off', 'wp-serverinfo');
388 }
389 return $magic_quotes_gpc;
390 }
391 }
392
393
394 ### Function: Get PHP Max Upload Size
395 if(!function_exists('get_php_upload_max')) {
396 function get_php_upload_max() {
397 if(ini_get('upload_max_filesize')) {
398 $upload_max = ini_get('upload_max_filesize');
399 } else {
400 $upload_max = __('N/A', 'wp-serverinfo');
401 }
402 return $upload_max;
403 }
404 }
405
406
407 ### Function: Get PHP Max Post Size
408 if(!function_exists('get_php_post_max')) {
409 function get_php_post_max() {
410 if(ini_get('post_max_size')) {
411 $post_max = ini_get('post_max_size');
412 } else {
413 $post_max = __('N/A', 'wp-serverinfo');
414 }
415 return $post_max;
416 }
417 }
418
419
420 ### Function: PHP Maximum Execution Time
421 if(!function_exists('get_php_max_execution')) {
422 function get_php_max_execution() {
423 if(ini_get('max_execution_time')) {
424 $max_execute = ini_get('max_execution_time');
425 } else {
426 $max_execute = __('N/A', 'wp-serverinfo');
427 }
428 return $max_execute;
429 }
430 }
431
432
433 ### Function: PHP Memory Limit
434 if(!function_exists('get_php_memory_limit')) {
435 function get_php_memory_limit() {
436 if(ini_get('memory_limit')) {
437 $memory_limit = ini_get('memory_limit');
438 } else {
439 $memory_limit = __('N/A', 'wp-serverinfo');
440 }
441 return $memory_limit;
442 }
443 }
444
445
446 ### Function: Get MYSQL Version
447 if(!function_exists('get_mysql_version')) {
448 function get_mysql_version() {
449 global $wpdb;
450 return $wpdb->get_var("SELECT VERSION() AS version");
451 }
452 }
453
454
455 ### Function: Get MYSQL Data Usage
456 if(!function_exists('get_mysql_data_usage')) {
457 function get_mysql_data_usage() {
458 global $wpdb;
459 $data_usage = 0;
460 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
461 foreach($tablesstatus as $tablestatus) {
462 $data_usage += $tablestatus->Data_length;
463 }
464
465 return $data_usage;
466 }
467 }
468
469
470 ### Function: Get MYSQL Index Usage
471 if(!function_exists('get_mysql_index_usage')) {
472 function get_mysql_index_usage() {
473 global $wpdb;
474 $index_usage = 0;
475 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
476 foreach($tablesstatus as $tablestatus) {
477 $index_usage += $tablestatus->Index_length;
478 }
479
480 return $index_usage;
481 }
482 }
483
484
485 ### Function: Get MYSQL Max Allowed Packet
486 if(!function_exists('get_mysql_max_allowed_packet')) {
487 function get_mysql_max_allowed_packet() {
488 global $wpdb;
489 $packet_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_allowed_packet'");
490
491 return $packet_max_query->Value;
492 }
493 }
494
495
496 ### Function:Get MYSQL Max Allowed Connections
497 if(!function_exists('get_mysql_max_allowed_connections')) {
498 function get_mysql_max_allowed_connections() {
499 global $wpdb;
500 $connection_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_connections'");
501
502 return $connection_max_query->Value;
503 }
504 }
505
506 ### Function:Get MYSQL Query Cache Size
507 if(!function_exists('get_mysql_query_cache_size')) {
508 function get_mysql_query_cache_size() {
509 global $wpdb;
510 $query_cache_size_query = $wpdb->get_row( "SHOW VARIABLES LIKE 'query_cache_size'" );
511
512 return $query_cache_size_query->Value;
513 }
514 }
515
516
517 ### Function: Get GD Version
518 if(!function_exists('get_gd_version')) {
519 function get_gd_version() {
520 if (function_exists('gd_info')) {
521 $gd = gd_info();
522 $gd = $gd["GD Version"];
523 } else {
524 ob_start();
525 phpinfo(8);
526 $phpinfo = ob_get_contents();
527 ob_end_clean();
528 $phpinfo = strip_tags($phpinfo);
529 $phpinfo = stristr($phpinfo,"gd version");
530 $phpinfo = stristr($phpinfo,"version");
531 $gd = substr($phpinfo,0,strpos($phpinfo,"\n"));
532 }
533 if(empty($gd)) {
534 $gd = __('N/A', 'wp-serverinfo');
535 }
536 return $gd;
537 }
538 }
539
540
541 ### Function: Get The Server Load
542 if(!function_exists('get_serverload')) {
543 function get_serverload() {
544 $server_load = '';
545 if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
546 if(@file_exists('/proc/loadavg') ) {
547 if ($fh = @fopen( '/proc/loadavg', 'r' )) {
548 $data = @fread( $fh, 6 );
549 @fclose( $fh );
550 $load_avg = explode( " ", $data );
551 $server_load = trim($load_avg[0]);
552 }
553 } else {
554 $data = @system('uptime');
555 preg_match('/(.*):{1}(.*)/', $data, $matches);
556 $load_arr = explode(',', $matches[2]);
557 $server_load = trim($load_arr[0]);
558 }
559 }
560 if(empty($server_load)) {
561 $server_load = __('N/A', 'wp-serverinfo');
562 }
563 return $server_load;
564 }
565 }
566
567
568 ### Function: Register ServerInfo Dashboard Widget
569 add_action('wp_dashboard_setup', 'serverinfo_register_dashboard_widget');
570 function serverinfo_register_dashboard_widget() {
571 if(current_user_can('manage_options')) {
572 wp_add_dashboard_widget('dashboard_serverinfo', __('Server Information', 'wp-serverinfo'), 'wp_dashboard_serverinfo');
573 }
574 }
575
576
577 ### Function: Print ServerInfo Dashboard Widget
578 function wp_dashboard_serverinfo() {
579 if( is_rtl() ) {
580 echo '<style type="text/css"> #wp-serverinfo ul { padding-left: 15px !important; } </style>';
581 echo '<div id="wp-serverinfo" style="direction: ltr; text-align: left;">';
582 } else {
583 echo '<div id="wp-serverinfo">';
584 }
585 echo '<p><strong>'.__('General', 'wp-serverinfo').'</strong></p>';
586 echo '<ul>';
587 echo '<li>'. __('OS', 'wp-serverinfo').': <strong>'.PHP_OS.'</strong></li>';
588 echo '<li>'. __('Server', 'wp-serverinfo').': <strong>'.$_SERVER["SERVER_SOFTWARE"].'</strong></li>';
589 echo '<li>'. __('Hostname', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_NAME'].'</strong></li>';
590 echo '<li>'. __('IP:Port', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT'].'</strong></li>';
591 echo '<li>'. __('Document Root', 'wp-serverinfo').': <strong>'.$_SERVER['DOCUMENT_ROOT'].'</strong></li>';
592 echo '</ul>';
593 echo '<p><strong>PHP</strong></p>';
594 echo '<ul>';
595 echo '<li>v<strong>'.PHP_VERSION.'</strong></li>';
596 echo '<li>GD: <strong>'.get_gd_version().'</strong></li>';
597 echo '<li>'. __('Magic Quotes GPC', 'wp-serverinfo').': <strong>'.get_php_magic_quotes_gpc().'</strong></li>';
598 echo '<li>'. __('Memory Limit', 'wp-serverinfo').': <strong>'.format_php_size(get_php_memory_limit()).'</strong></li>';
599 echo '<li>'. __('Max Upload Size', 'wp-serverinfo').': <strong>'.format_php_size(get_php_upload_max()).'</strong></li>';
600 echo '</ul>';
601 echo '<p><strong>MYSQL</strong></p>';
602 echo '<ul>';
603 echo '<li>v<strong>'.get_mysql_version().'</strong></li>';
604 echo '<li>'. __('Maximum No. Connections', 'wp-serverinfo').': <strong>'.number_format_i18n(get_mysql_max_allowed_connections(), 0).'</strong></li>';
605 echo '<li>'. __('Maximum Packet Size', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_max_allowed_packet()).'</strong></li>';
606 echo '<li>'. __('Data Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_data_usage()).'</strong></li>';
607 echo '<li>'. __('Index Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_index_usage()).'</strong></li>';
608 echo '</ul>';
609 echo '<p class="textright"><a href="'.admin_url('index.php?page=wp-serverinfo/wp-serverinfo.php').'" class="button">'.__('View all', 'wp-serverinfo').'</a></p>';
610 echo '</div>';
611 }
612