PluginProbe
WP-ServerInfo / 1.66
WP-ServerInfo v1.66
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.66, at wp-serverinfo.php

594 lines 29.4 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.66
7 Author: Lester 'GaMerZ' Chan
8 Author URI: https://lesterchan.net
9 Text Domain: wp-serverinfo
10 */
11
12
13 /*
14 Copyright 2020 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 Max Script Execute Time', 'wp-serverinfo'); ?></td>
138 <td><?php echo get_php_max_execution(); ?>s</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 Date/Time', 'wp-serverinfo'); ?></td>
148 <td><?php echo mysql2date(sprintf(__('%s @ %s', 'wp-postratings'), get_option('date_format'), get_option('time_format')), current_time('mysql')); ?></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 </tbody>
159 </table>
160 </div>
161 <?php
162 }
163
164
165 ### Get PHP Information
166 function get_phpinfo() {
167 if( ! class_exists( 'DOMDocument' ) ) {
168 echo '<div class="wrap" id="PHPinfo" style="display: none;">';
169 echo '<h2>PHP ' . phpversion() . '</h2>';
170 serverinfo_subnavi();
171 echo 'You need <a href="http://php.net/manual/en/class.domdocument.php" target="_blank">DOMDocument extension</a> to be enabled.';
172 echo '</div>';
173 } else {
174 ob_start();
175 phpinfo();
176 $phpinfo = ob_get_contents();
177 ob_end_clean();
178
179 // Use DOMDocument to parse phpinfo()
180 $html = new DOMDocument( '1.0', 'UTF-8' );
181 $html->loadHTML( $phpinfo );
182
183 // Style process
184 $tables = $html->getElementsByTagName( 'table' );
185 foreach( $tables as $table ) {
186 $table->setAttribute( 'class', 'widefat' );
187 }
188
189 // We only need the <body>
190 $xpath = new DOMXPath($html);
191 $body = $xpath->query('/html/body');
192
193 // Save HTML fragment
194 $phpinfo_html = $html->saveXml( $body->item( 0 ) );
195
196 echo '<div class="wrap" id="PHPinfo" style="display: none;">';
197 echo '<h2>PHP ' . phpversion() . '</h2>';
198 serverinfo_subnavi();
199 echo $phpinfo_html;
200 echo '</div>';
201 }
202 }
203
204
205 ### Get MYSQL Information
206 function get_mysqlinfo() {
207 global $wpdb;
208 $sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
209 $mysqlinfo = $wpdb->get_results("SHOW VARIABLES");
210 if( is_rtl() ) : ?>
211 <style type="text/css">
212 #MYSQLinfo,
213 #MYSQLinfo table,
214 #MYSQLinfo th,
215 #MYSQLinfo td {
216 direction: ltr;
217 text-align: left;
218 }
219 #MYSQLinfo h2 {
220 padding: 0.5em 0 0;
221 }
222 </style>
223 <?php endif;
224 echo '<div class="wrap" id="MYSQLinfo" style="display: none;">'."\n";
225 echo "<h2>MYSQL $sqlversion</h2>\n";
226 serverinfo_subnavi();
227 if($mysqlinfo) {
228 echo '<br class="clear" />'."\n";
229 echo '<table class="widefat" dir="ltr">'."\n";
230 echo '<thead><tr><th>'.__('Variable Name', 'wp-serverinfo').'</th><th>'.__('Value', 'wp-serverinfo').'</th></tr></thead><tbody>'."\n";
231 foreach($mysqlinfo as $info) {
232 echo '<tr class="" onmouseover="this.className=\'highlight\'" onmouseout="this.className=\'\'"><td>'.$info->Variable_name.'</td><td>'.htmlspecialchars($info->Value).'</td></tr>'."\n";
233 }
234 echo '</tbody></table>'."\n";
235 }
236 echo '</div>'."\n";
237 }
238
239
240 ### Get memcached Information (Description from https://boxpanel.blueboxgrp.com/public/the_vault/index.php/memcached_Tips)
241 function get_memcachedinfo() {
242 echo '<div class="wrap" id="memcachedinfo" style="display: none;">'."\n";
243 if(class_exists('Memcache')) {
244 $memcached_obj = new Memcache;
245 $memcached_obj->addServer('localhost', 11211);
246 $memcachedinfo = $memcached_obj->getStats();
247 if( is_rtl() ) : ?>
248 <style type="text/css">
249 #memcachedinfo,
250 #memcachedinfo table,
251 #memcachedinfo th,
252 #memcachedinfo td {
253 direction: ltr;
254 text-align: left;
255 }
256 #memcachedinfo h2 {
257 padding: 0.5em 0 0;
258 }
259 </style>
260 <?php endif;
261 echo "<h2>memcached {$memcachedinfo['version']}</h2>\n";
262 serverinfo_subnavi();
263 if($memcachedinfo) {
264 $cache_hit= ( $memcachedinfo['cmd_get'] > 0 ? ( ( $memcachedinfo['get_hits'] / $memcachedinfo['cmd_get'] ) * 100 ) : 0 );
265 $cache_hit = round($cache_hit, 2);
266 $cache_miss = 100 - $cache_hit;
267
268 $usage = round((($memcachedinfo['bytes']/$memcachedinfo['limit_maxbytes']) * 100), 2);
269 $uptime = number_format_i18n(($memcachedinfo['uptime']/60/60/24));
270
271 echo '<br class="clear" />'."\n";
272 echo '<table class="widefat" dir="ltr">'."\n";
273 echo '<thead><tr><th>'.__('Variable Name', 'wp-serverinfo').'</th><th>'.__('Value', 'wp-serverinfo').'</th><th>'.__('Description', 'wp-serverinfo').'</th></tr></thead><tbody>'."\n";
274 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";
275 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";
276 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";
277 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";
278 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";
279 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";
280 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";
281 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";
282 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";
283 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";
284 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";
285 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";
286 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";
287 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";
288 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";
289 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";
290 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";
291 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";
292 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";
293 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";
294 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";
295 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";
296 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";
297 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";
298 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";
299 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";
300 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";
301 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";
302 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";
303 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";
304 echo '</tbody></table>'."\n";
305 }
306 }
307 echo '</div>'."\n";
308 }
309
310
311 ### WP-Server Sub Navigation
312 function serverinfo_subnavi($display = true) {
313 $output = '<p style="text-align: center">';
314 $output .= '<a href="#DisplayGeneral" onclick="toggle_general(); return false;">'.__('Display General Overview', 'wp-serverinfo').'</a>';
315 $output .= ' - <a href="#DisplayPHP" onclick="toggle_php(); return false;">'.__('Display PHP Information', 'wp-serverinfo').'</a>';
316 $output .= ' - <a href="#DisplayMYSQL" onclick="toggle_mysql(); return false;">'.__('Display MYSQL Information', 'wp-serverinfo').'</a>';
317 if(class_exists('Memcache')) {
318 $output .= ' - <a href="#Displaymemcached" onclick="toggle_memcached(); return false;">'.__('Display memcached Information', 'wp-serverinfo').'</a>';
319 }
320 $output .= '</p>';
321 if($display) {
322 echo $output;
323 } else {
324 return $output;
325 }
326 }
327
328
329 ### Function: Format Bytes Into TiB/GiB/MiB/KiB/Bytes
330 if(!function_exists('format_filesize')) {
331 function format_filesize($rawSize) {
332 if($rawSize / 1099511627776 > 1) {
333 return number_format_i18n($rawSize/1099511627776, 1).' '.__('TiB', 'wp-serverinfo');
334 } elseif($rawSize / 1073741824 > 1) {
335 return number_format_i18n($rawSize/1073741824, 1).' '.__('GiB', 'wp-serverinfo');
336 } elseif($rawSize / 1048576 > 1) {
337 return number_format_i18n($rawSize/1048576, 1).' '.__('MiB', 'wp-serverinfo');
338 } elseif($rawSize / 1024 > 1) {
339 return number_format_i18n($rawSize/1024, 1).' '.__('KiB', 'wp-serverinfo');
340 } elseif($rawSize > 1) {
341 return number_format_i18n($rawSize, 0).' '.__('bytes', 'wp-serverinfo');
342 } else {
343 return __('unknown', 'wp-serverinfo');
344 }
345 }
346 }
347
348 ### Function: Convert PHP Size Format to Localized
349 function format_php_size($size) {
350 if (!is_numeric($size)) {
351 if (strpos($size, 'M') !== false) {
352 $size = intval($size)*1024*1024;
353 } elseif (strpos($size, 'K') !== false) {
354 $size = intval($size)*1024;
355 } elseif (strpos($size, 'G') !== false) {
356 $size = intval($size)*1024*1024*1024;
357 }
358 }
359 return is_numeric($size) ? format_filesize($size) : $size;
360 }
361
362 ### Function: Get PHP Short Tag
363 if(!function_exists('get_php_short_tag')) {
364 function get_php_short_tag() {
365 if(ini_get('short_open_tag')) {
366 $short_tag = __('On', 'wp-serverinfo');
367 } else {
368 $short_tag = __('Off', 'wp-serverinfo');
369 }
370 return $short_tag;
371 }
372 }
373
374
375 ### Function: Get PHP Max Upload Size
376 if(!function_exists('get_php_upload_max')) {
377 function get_php_upload_max() {
378 if(ini_get('upload_max_filesize')) {
379 $upload_max = ini_get('upload_max_filesize');
380 } else {
381 $upload_max = __('N/A', 'wp-serverinfo');
382 }
383 return $upload_max;
384 }
385 }
386
387
388 ### Function: Get PHP Max Post Size
389 if(!function_exists('get_php_post_max')) {
390 function get_php_post_max() {
391 if(ini_get('post_max_size')) {
392 $post_max = ini_get('post_max_size');
393 } else {
394 $post_max = __('N/A', 'wp-serverinfo');
395 }
396 return $post_max;
397 }
398 }
399
400
401 ### Function: PHP Maximum Execution Time
402 if(!function_exists('get_php_max_execution')) {
403 function get_php_max_execution() {
404 if(ini_get('max_execution_time')) {
405 $max_execute = ini_get('max_execution_time');
406 } else {
407 $max_execute = __('N/A', 'wp-serverinfo');
408 }
409 return $max_execute;
410 }
411 }
412
413
414 ### Function: PHP Memory Limit
415 if(!function_exists('get_php_memory_limit')) {
416 function get_php_memory_limit() {
417 if(ini_get('memory_limit')) {
418 $memory_limit = ini_get('memory_limit');
419 } else {
420 $memory_limit = __('N/A', 'wp-serverinfo');
421 }
422 return $memory_limit;
423 }
424 }
425
426
427 ### Function: Get MYSQL Version
428 if(!function_exists('get_mysql_version')) {
429 function get_mysql_version() {
430 global $wpdb;
431 return $wpdb->get_var("SELECT VERSION() AS version");
432 }
433 }
434
435
436 ### Function: Get MYSQL Data Usage
437 if(!function_exists('get_mysql_data_usage')) {
438 function get_mysql_data_usage() {
439 global $wpdb;
440 $data_usage = 0;
441 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
442 foreach($tablesstatus as $tablestatus) {
443 $data_usage += $tablestatus->Data_length;
444 }
445
446 return $data_usage;
447 }
448 }
449
450
451 ### Function: Get MYSQL Index Usage
452 if(!function_exists('get_mysql_index_usage')) {
453 function get_mysql_index_usage() {
454 global $wpdb;
455 $index_usage = 0;
456 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
457 foreach($tablesstatus as $tablestatus) {
458 $index_usage += $tablestatus->Index_length;
459 }
460
461 return $index_usage;
462 }
463 }
464
465
466 ### Function: Get MYSQL Max Allowed Packet
467 if(!function_exists('get_mysql_max_allowed_packet')) {
468 function get_mysql_max_allowed_packet() {
469 global $wpdb;
470 $packet_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_allowed_packet'");
471
472 return $packet_max_query->Value;
473 }
474 }
475
476
477 ### Function:Get MYSQL Max Allowed Connections
478 if(!function_exists('get_mysql_max_allowed_connections')) {
479 function get_mysql_max_allowed_connections() {
480 global $wpdb;
481 $connection_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_connections'");
482
483 return $connection_max_query->Value;
484 }
485 }
486
487 ### Function:Get MYSQL Query Cache Size
488 if(!function_exists('get_mysql_query_cache_size')) {
489 function get_mysql_query_cache_size() {
490 global $wpdb;
491 $query_cache_size_query = $wpdb->get_row( "SHOW VARIABLES LIKE 'query_cache_size'" );
492
493 return $query_cache_size_query->Value;
494 }
495 }
496
497
498 ### Function: Get GD Version
499 if(!function_exists('get_gd_version')) {
500 function get_gd_version() {
501 if (function_exists('gd_info')) {
502 $gd = gd_info();
503 $gd = $gd["GD Version"];
504 } else {
505 ob_start();
506 phpinfo(8);
507 $phpinfo = ob_get_contents();
508 ob_end_clean();
509 $phpinfo = strip_tags($phpinfo);
510 $phpinfo = stristr($phpinfo,"gd version");
511 $phpinfo = stristr($phpinfo,"version");
512 $gd = substr($phpinfo,0,strpos($phpinfo,"\n"));
513 }
514 if(empty($gd)) {
515 $gd = __('N/A', 'wp-serverinfo');
516 }
517 return $gd;
518 }
519 }
520
521
522 ### Function: Get The Server Load
523 if(!function_exists('get_serverload')) {
524 function get_serverload() {
525 $server_load = '';
526 if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
527 if(@file_exists('/proc/loadavg') ) {
528 if ($fh = @fopen( '/proc/loadavg', 'r' )) {
529 $data = @fread( $fh, 6 );
530 @fclose( $fh );
531 $load_avg = explode( " ", $data );
532 $server_load = trim($load_avg[0]);
533 }
534 } else {
535 $data = @system('uptime');
536 preg_match('/(.*):{1}(.*)/', $data, $matches);
537 $load_arr = explode(',', $matches[2]);
538 $server_load = trim($load_arr[0]);
539 }
540 }
541 if(empty($server_load)) {
542 $server_load = __('N/A', 'wp-serverinfo');
543 }
544 return $server_load;
545 }
546 }
547
548
549 ### Function: Register ServerInfo Dashboard Widget
550 add_action('wp_dashboard_setup', 'serverinfo_register_dashboard_widget');
551 function serverinfo_register_dashboard_widget() {
552 if(current_user_can('manage_options')) {
553 wp_add_dashboard_widget('dashboard_serverinfo', __('Server Information', 'wp-serverinfo'), 'wp_dashboard_serverinfo');
554 }
555 }
556
557
558 ### Function: Print ServerInfo Dashboard Widget
559 function wp_dashboard_serverinfo() {
560 if( is_rtl() ) {
561 echo '<style type="text/css"> #wp-serverinfo ul { padding-left: 15px !important; } </style>';
562 echo '<div id="wp-serverinfo" style="direction: ltr; text-align: left;">';
563 } else {
564 echo '<div id="wp-serverinfo">';
565 }
566 echo '<p><strong>'.__('General', 'wp-serverinfo').'</strong></p>';
567 echo '<ul>';
568 echo '<li>'. __('OS', 'wp-serverinfo').': <strong>'.PHP_OS.'</strong></li>';
569 echo '<li>'. __('Server', 'wp-serverinfo').': <strong>'.$_SERVER["SERVER_SOFTWARE"].'</strong></li>';
570 echo '<li>'. __('Hostname', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_NAME'].'</strong></li>';
571 echo '<li>'. __('IP:Port', 'wp-serverinfo').': <strong>'.$_SERVER['SERVER_ADDR'].':'.$_SERVER['SERVER_PORT'].'</strong></li>';
572 echo '<li>'. __('Document Root', 'wp-serverinfo').': <strong>'.$_SERVER['DOCUMENT_ROOT'].'</strong></li>';
573 echo '</ul>';
574 echo '<p><strong>PHP</strong></p>';
575 echo '<ul>';
576 echo '<li>v<strong>'.PHP_VERSION.'</strong></li>';
577 echo '<li>GD: <strong>'.get_gd_version().'</strong></li>';
578 echo '<li>'. __('Memory Limit', 'wp-serverinfo').': <strong>'.format_php_size(get_php_memory_limit()).'</strong></li>';
579 echo '<li>'. __('Max Script Execute Time', 'wp-serverinfo').': <strong>'.get_php_max_execution().'s</strong></li>';
580 echo '<li>'. __('Max Post Size', 'wp-serverinfo').': <strong>'. format_php_size(get_php_post_max()).'</strong></li>';
581 echo '<li>'. __('Max Upload Size', 'wp-serverinfo').': <strong>'.format_php_size(get_php_upload_max()).'</strong></li>';
582 echo '</ul>';
583 echo '<p><strong>MYSQL</strong></p>';
584 echo '<ul>';
585 echo '<li>v<strong>'.get_mysql_version().'</strong></li>';
586 echo '<li>'. __('Maximum No. Connections', 'wp-serverinfo').': <strong>'.number_format_i18n(get_mysql_max_allowed_connections(), 0).'</strong></li>';
587 echo '<li>'. __('Maximum Packet Size', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_max_allowed_packet()).'</strong></li>';
588 echo '<li>'. __('Data Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_data_usage()).'</strong></li>';
589 echo '<li>'. __('Index Disk Usage', 'wp-serverinfo').': <strong>'.format_filesize(get_mysql_index_usage()).'</strong></li>';
590 echo '</ul>';
591 echo '<p class="textright"><a href="'.admin_url('index.php?page=wp-serverinfo/wp-serverinfo.php').'" class="button">'.__('View all', 'wp-serverinfo').'</a></p>';
592 echo '</div>';
593 }
594