PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.6.4
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.6.4
1.9.5 1.9.4 1.9.3 trunk 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 All 40 releases
code-profiler / lib / class-troubleshooter.php

class-troubleshooter.php in Code Profiler – WordPress Performance Profiling and Debugging Made Easy 1.6.4, at lib/class-troubleshooter.php

338 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +=====================================================================+
4 | ____ _ ____ __ _ _ |
5 | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ |
6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 | |
10 | (c) Jerome Bruandet ~ https://code-profiler.com/ |
11 +=====================================================================+
12 */
13
14 if (! defined('ABSPATH') ) { die('Forbidden'); }
15
16 // =====================================================================
17
18 class CP_Troubleshooter {
19
20 /********************************************************************
21 * Array to handle all results
22 */
23 private $buffer = [];
24
25 /********************************************************************
26 * Initialize.
27 */
28 public function __construct() {
29
30 $this->get_system_info('sysinfo');
31 $this->cp_info('code-profiler');
32 $this->function_exists('code-profiler');
33 $this->check_wpdb('wpdb');
34 $this->check_proxy('proxy');
35 $this->get_all_plugins('plugins');
36 $this->get_theme('themes');
37 $this->get_cp_config();
38
39 echo esc_textarea( print_r( $this->buffer, true ) );
40 }
41
42 /********************************************************************
43 * Retrieve system info:
44 * * PHP version
45 * * PHP SAPI
46 * * HTTP server
47 * * Opcode cache
48 * * PHP directives (time limit, memory available, temp dir etc)
49 * * PHP last error
50 * * WordPress
51 */
52 private function get_system_info( $key ) {
53
54 $this->buffer[ $key ]['OS'] = php_uname();
55
56 if (! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
57 $this->buffer[ $key ]['HTTP server'] = $_SERVER['SERVER_SOFTWARE'];
58 } else {
59 $this->buffer[ $key ]['HTTP server'] = 'N/A';
60 }
61
62 $this->buffer[ $key ]['PHP'] = strtoupper( PHP_SAPI ) .' '. PHP_VERSION;
63
64 if ( extension_loaded('Zend OPcache') ) {
65 $this->buffer[ $key ]['Opcode cache'] = sprintf(
66 'Zend OPcache (%s)', ini_get('opcache.enable') ? 'enabled':'disabled'
67 );
68 } elseif ( extension_loaded('wincache') ) {
69 $this->buffer[ $key ]['Opcode cache'] = sprintf(
70 'wincache (%s)', ini_get('wincache.fcenabled') ? 'enabled':'disabled'
71 );
72 }
73
74 $this->buffer[ $key ]['Memory limit'] = ini_get('memory_limit');
75 $this->buffer[ $key ]['Peak limit'] = number_format( memory_get_peak_usage() );
76 $this->buffer[ $key ]['Max execution time'] = ini_get('max_execution_time') .'s';
77 $this->buffer[ $key ]['Disabled functions'] = ini_get('disable_functions');
78 $this->buffer[ $key ]['Display errors'] = ini_get('display_errors');
79
80 $tmp = ini_get('sys_temp_dir');
81 if (! empty( $tmp ) ) {
82 if ( is_writable( $tmp ) ) {
83 $tmp .= ' (writable)';
84 } else {
85 $tmp .= ' (not writable!)';
86 }
87 }
88 $tmp = $this->shorten_path( $tmp );
89 $this->buffer[ $key ]['Temp directory'] = $tmp;
90 $this->buffer[ $key ]['Log errors'] = ini_get('log_errors');
91
92 $error_log = ini_get('error_log');
93 $filesize = 0;
94 if ( is_file( $error_log ) ) {
95 $filesize = filesize( $error_log );
96 }
97 $this->buffer[ $key ]['Error log'] = "$error_log (". number_format( $filesize ) ." bytes)";
98
99 $this->buffer[ $key ]['Last error'] = error_get_last();
100 if ( isset( $this->buffer[ $key ]['Last error']['file'] ) ) {
101 $this->buffer[ $key ]['Last error']['file'] = $this->shorten_path( $this->buffer[ $key ]['Last error']['file'] );
102 }
103
104 // WordPress
105 if ( defined('WP_MEMORY_LIMIT') ) {
106 $this->buffer[ $key ]['WordPress']['WP_MEMORY_LIMIT'] = WP_MEMORY_LIMIT;
107 } else {
108 $this->buffer[ $key ]['WordPress']['WP_MEMORY_LIMIT'] = 'N/A';
109 }
110 if ( defined('WP_MAX_MEMORY_LIMIT') ) {
111 $this->buffer[ $key ]['WordPress']['WP_MAX_MEMORY_LIMIT'] = WP_MAX_MEMORY_LIMIT;
112 } else {
113 $this->buffer[ $key ]['WordPress']['WP_MAX_MEMORY_LIMIT'] = 'N/A';
114 }
115 global $wp_version;
116 $this->buffer[ $key ]['WordPress']['version'] = $wp_version;
117 $wp_debug = '';
118 if ( defined('WP_DEBUG') ) {
119 $wp_debug = WP_DEBUG;
120 }
121 $this->buffer[ $key ]['WordPress']['WP_DEBUG'] = $wp_debug;
122 $wp_debug = '';
123 $filesize = 0;
124 if ( defined('WP_DEBUG_LOG') ) {
125 $wp_debug = WP_DEBUG_LOG;
126 }
127 if ( is_file( $wp_debug ) ) {
128 $filesize = filesize( $error_log );
129 $wp_debug = $this->shorten_path( $wp_debug ) ." (". number_format( $filesize ) ." bytes)";
130 }
131 $this->buffer[ $key ]['WordPress']['WP_DEBUG_LOG'] = $wp_debug;
132
133 }
134
135 /********************************************************************
136 * Verify if some important PHP functions are available.
137 */
138 private function function_exists( $key ) {
139
140 $required_functions = [
141 'register_shutdown_function' => 'shutdown',
142 'register_tick_function' => 'tick',
143 'stream_wrapper_unregister' => 'unregister',
144 'stream_wrapper_register' => 'register',
145 'stream_wrapper_restore' => 'restore'
146 ];
147
148 foreach ( $required_functions as $function => $value ) {
149 $this->buffer[ $key ][ $value ] = function_exists( $function );
150 }
151 }
152
153
154 /********************************************************************
155 * Return the version and type (free/pro) of Code Profiler.
156 */
157 private function cp_info( $key ) {
158
159 if ( defined('CODE_PROFILER_PRO_VERSION') ) {
160 $this->buffer[ $key ]['slug'] = 'code-profiler-pro';
161 $this->buffer[ $key ]['version'] = CODE_PROFILER_PRO_VERSION;
162
163 } elseif ( defined('CODE_PROFILER_VERSION') ) {
164 $this->buffer[ $key ]['slug'] = 'code-profiler';
165 $this->buffer[ $key ]['version'] = CODE_PROFILER_VERSION;
166
167 } else {
168 exit('Error: Code Profiler is not active. Please activate it and run this script again.');
169
170 }
171
172 // Data folder must be writable
173 $upload_dir = wp_upload_dir();
174 $dir = $upload_dir['basedir'] .'/'. $this->buffer[ $key ]['slug'];
175
176 $this->buffer[ $key ]['data_dir']['path'] = $this->shorten_path( $dir );
177 $this->buffer[ $key ]['data_dir']['exists'] = file_exists( $dir );
178 $this->buffer[ $key ]['data_dir']['writable'] = is_writable( $dir );
179 }
180
181
182 /********************************************************************
183 * Check if there are subclasses of the wpdb class and
184 * look for wp-content/db.php
185 */
186 function check_wpdb( $key ) {
187
188 foreach( get_declared_classes() as $class ) {
189 $reflected = new ReflectionClass( $class );
190 if ( $reflected->isSubclassOf('wpdb') ) {
191 $script = $reflected->getFileName();
192 $this->buffer[ $key ]['extends'][$class] = $this->shorten_path( $script );
193 }
194 }
195 $db_php = $this->shorten_path( WP_CONTENT_DIR .'/db.php');
196 $this->buffer[ $key ][ $db_php ] = file_exists( WP_CONTENT_DIR .'/db.php');
197 }
198
199
200 /********************************************************************
201 * Check for advanced cache
202 */
203 private function check_cache( $key ) {
204
205 $this->buffer[ $key ]['cache'] = defined('WP_CACHE') && file_exists(WP_CONTENT_DIR . '/advanced-cache.php');
206 }
207
208
209 /********************************************************************
210 * Check for reverse proxy or CDN
211 */
212 private function check_proxy( $key ) {
213
214 $this->buffer[ $key ] = [];
215 $proxies = [
216 'HTTP_X_FORWARDED_FOR',
217 'HTTP_CF_CONNECTING_IP',
218 'HTTP_INCAP_CLIENT_IP'
219 ];
220
221 foreach( $proxies as $proxy ) {
222 if (! empty( $_SERVER[ $proxy ] ) ) {
223 $this->buffer[ $key ][ $proxy ] = 1;
224 }
225 }
226
227 }
228
229
230 /********************************************************************
231 * Retrieve the list of all plugins and sort them
232 * (active or disabled).
233 */
234 private function get_all_plugins( $key ) {
235
236 if (! function_exists('get_plugins') ) {
237 require_once ABSPATH .'wp-admin/includes/plugin.php';
238 }
239 $plugins = get_plugins();
240 foreach( $plugins as $k => $v ) {
241 if ( $slug = substr( $k, 0, strpos( $k, '/') ) ) {
242 $name = 'N/A'; $version = 'N/A'; $uri = 'N/A';
243 if (! empty( $v['Name'] ) ) {
244 $name = $v['Name'];
245 }
246 if (! empty( $v['Version'] ) ) {
247 $version = $v['Version'];
248 }
249 if (! empty( $v['PluginURI'] ) ) {
250 $uri = $v['PluginURI'];
251 }
252 if ( is_plugin_active( $k ) ) {
253 $this->buffer[ $key ]['active'][ $slug ] = "$name - $version - $uri";
254
255 } else {
256 $this->buffer[ $key ]['inactive'][ $slug ] = "$name - $version - $uri";
257 }
258 }
259 }
260
261 $mu_plugins = get_mu_plugins();
262 foreach( $mu_plugins as $k => $v ) {
263 $name = 'N/A'; $version = 'N/A'; $uri = 'N/A';
264 if (! empty( $v['Name'] ) ) {
265 $name = $v['Name'];
266 }
267 if (! empty( $v['Version'] ) ) {
268 $version = $v['Version'];
269 }
270 if (! empty( $v['PluginURI'] ) ) {
271 $uri = $v['PluginURI'];
272 }
273 $this->buffer[ $key ]['mu-plugins'][ $k ] = "$name - $version - $uri";
274 }
275
276 }
277
278
279 /********************************************************************
280 * Retrieve the active theme.
281 */
282 private function get_theme( $key ) {
283
284 $themes = wp_get_themes();
285 $active = get_option('template');
286 foreach( $themes as $k => $v ) {
287 $name = 'N/A'; $version = 'N/A';
288 if ( $v->Name ) {
289 $name = $v->Name;
290 }
291 if ( $v->Version ) {
292 $version = $v->Version;
293 }
294 if ( $k == $active ) {
295 $this->buffer[ $key ]['active'][ $k ] = "$name - $version";
296 } else {
297 $this->buffer[ $key ]['inactive'][ $k ] = "$name - $version";
298 }
299 }
300 }
301
302
303 /********************************************************************
304 * Retrieve Code Profiler's configuration
305 */
306 private function get_cp_config() {
307
308 $cp_options = get_option('code-profiler');
309
310 $list = [
311 'hide_empty_value',
312 'warn_composer',
313 'enable_wpcli',
314 'disable_wpcron',
315 // 'disable_db-php',
316 'http_response',
317 // 'backtrace_limit',
318 'accuracy',
319 'buffer'
320 ];
321 foreach( $list as $element ) {
322 $this->buffer['options'][ $element ] = isset( $cp_options[ $element ] )? $cp_options[ $element ]:0;
323 }
324 }
325
326 /********************************************************************
327 * Remove the ABSPATH from a path
328 */
329 private function shorten_path( $path ) {
330
331 return str_replace( ABSPATH, '', $path );
332 }
333
334 }
335
336 // =====================================================================
337 // EOF
338