PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.5.1
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.5.1
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.5.1, at lib/class-troubleshooter.php

266 lines 7.1 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('functions');
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 */
51 private function get_system_info( $key ) {
52
53 $this->buffer[ $key ]['OS'] = php_uname();
54
55 if (! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
56 $this->buffer[ $key ]['HTTP server'] = $_SERVER['SERVER_SOFTWARE'];
57 } else {
58 $this->buffer[ $key ]['HTTP server'] = 'N/A';
59 }
60
61 $this->buffer[ $key ]['PHP'] = strtoupper( PHP_SAPI ) .' '. PHP_VERSION;
62
63 if ( extension_loaded('Zend OPcache') ) {
64 $this->buffer[ $key ]['Opcode cache'] = sprintf(
65 'Zend OPcache (%s)', ini_get('opcache.enable') ? 'enabled':'disabled'
66 );
67 } elseif ( extension_loaded('wincache') ) {
68 $this->buffer[ $key ]['Opcode cache'] = sprintf(
69 'wincache (%s)', ini_get('wincache.fcenabled') ? 'enabled':'disabled'
70 );
71 }
72
73 $this->buffer[ $key ]['Memory limit'] = ini_get('memory_limit');
74 $this->buffer[ $key ]['Peak limit'] = number_format( memory_get_peak_usage() );
75 $this->buffer[ $key ]['Max execution time'] = ini_get('max_execution_time') .'s';
76 $this->buffer[ $key ]['Disabled functions'] = ini_get('disable_functions');
77 $this->buffer[ $key ]['Display errors'] = ini_get('display_errors');
78
79 $tmp = ini_get('sys_temp_dir');
80 if (! empty( $tmp ) ) {
81 if ( is_writable( $tmp ) ) {
82 $tmp .= ' (writable)';
83 } else {
84 $tmp .= ' (not writable!)';
85 }
86 }
87 $tmp = $this->shorten_path( $tmp );
88 $this->buffer[ $key ]['Temp directory'] = $tmp;
89 $this->buffer[ $key ]['Log errors'] = ini_get('log_errors');
90 $this->buffer[ $key ]['Error log'] = ini_get('error_log');
91 $this->buffer[ $key ]['Last error'] = error_get_last();
92 if ( isset( $this->buffer[ $key ]['Last error']['file'] ) ) {
93 $this->buffer[ $key ]['Last error']['file'] = $this->shorten_path( $this->buffer[ $key ]['Last error']['file'] );
94 }
95 }
96
97
98 /**
99 * Verify if some important PHP functions are available.
100 */
101 private function function_exists( $key ) {
102
103 $required_functions = [
104 'register_shutdown_function' => 'shutdown',
105 'register_tick_function' => 'tick',
106 'stream_wrapper_unregister' => 'unregister',
107 'stream_wrapper_register' => 'register',
108 'stream_wrapper_restore' => 'restore'
109 ];
110
111 foreach ( $required_functions as $function => $value ) {
112 $this->buffer[ $key ][ $value ] = function_exists( $function );
113 }
114 }
115
116
117 /**
118 * Return the version and type (free/pro) of Code Profiler.
119 */
120 private function cp_info( $key ) {
121
122 if ( defined('CODE_PROFILER_PRO_VERSION') ) {
123 $this->buffer[ $key ]['slug'] = 'code-profiler-pro';
124 $this->buffer[ $key ]['version'] = CODE_PROFILER_PRO_VERSION;
125
126 } elseif ( defined('CODE_PROFILER_VERSION') ) {
127 $this->buffer[ $key ]['slug'] = 'code-profiler';
128 $this->buffer[ $key ]['version'] = CODE_PROFILER_VERSION;
129
130 } else {
131 exit('Error: Code Profiler is not active. Please activate it and run this script again.');
132
133 }
134
135 // Data folder must be writable
136 $upload_dir = wp_upload_dir();
137 $dir = $upload_dir['basedir'] .'/'. $this->buffer[ $key ]['slug'];
138
139 $this->buffer[ $key ]['data_dir']['path'] = $this->shorten_path( $dir );
140 $this->buffer[ $key ]['data_dir']['exists'] = file_exists( $dir );
141 $this->buffer[ $key ]['data_dir']['writable'] = is_writable( $dir );
142 }
143
144
145 /**
146 * Check if there are subclasses of the wpdb class and
147 * look for wp-content/db.php
148 */
149 function check_wpdb( $key ) {
150
151 foreach( get_declared_classes() as $class ) {
152 $reflected = new ReflectionClass( $class );
153 if ( $reflected->isSubclassOf('wpdb') ) {
154 $script = $reflected->getFileName();
155 $this->buffer[ $key ]['extends'][$class] = $this->shorten_path( $script );
156 }
157 }
158 $db_php = $this->shorten_path( WP_CONTENT_DIR .'/db.php');
159 $this->buffer[ $key ][ $db_php ] = file_exists( WP_CONTENT_DIR .'/db.php');
160 }
161
162
163 /**
164 * Check for advanced cache
165 */
166 private function check_cache( $key ) {
167
168 $this->buffer[ $key ]['cache'] = defined('WP_CACHE') && file_exists(WP_CONTENT_DIR . '/advanced-cache.php');
169 }
170
171
172 /**
173 * Check for reverse proxy or CDN
174 */
175 private function check_proxy( $key ) {
176
177 $this->buffer[ $key ] = [];
178 $proxies = [
179 'HTTP_X_FORWARDED_FOR',
180 'HTTP_CF_CONNECTING_IP',
181 'HTTP_INCAP_CLIENT_IP'
182 ];
183
184 foreach( $proxies as $proxy ) {
185 if (! empty( $_SERVER[ $proxy ] ) ) {
186 $this->buffer[ $key ][ $proxy ] = 1;
187 }
188 }
189
190 }
191
192
193 /**
194 * Retrieve the list of all plugins and sort them
195 * (active or disabled).
196 */
197 private function get_all_plugins( $key ) {
198
199 if (! function_exists('get_plugins') ) {
200 require_once ABSPATH .'wp-admin/includes/plugin.php';
201 }
202 $plugins = get_plugins();
203 foreach( $plugins as $k => $v ) {
204 if ( $slug = substr( $k, 0, strpos( $k, '/') ) ) {
205 $this->buffer[ $key ][ $slug ] = "{$v['Name']} - {$v['Version']}";
206 }
207 }
208
209 $mu_plugins = get_mu_plugins();
210 foreach( $mu_plugins as $k => $v ) {
211 $this->buffer[ $key ]['mu-plugins'][ $k ] = "{$v['Name']} - {$v['Version']}";
212 }
213
214 }
215
216
217 /**
218 * Retrieve the active theme.
219 */
220 private function get_theme( $key ) {
221
222 $themes = wp_get_themes();
223 $active = get_option('template');
224 foreach( $themes as $k => $v ) {
225 $version = $v->Version;
226 if ( $k == $active ) {
227 $version .= ' (active)';
228 }
229 $this->buffer[ $key ][ $k ] = "{$v->Name} - $version";
230 }
231 }
232
233
234 /**
235 * Retrieve Code Profiler's configuration
236 */
237 private function get_cp_config() {
238
239 $cp_options = get_option('code-profiler');
240
241 $list = [
242 'hide_empty_value',
243 'warn_composer',
244 'enable_wpcli',
245 'disable_wpcron',
246 // 'disable_db-php',
247 'http_response'
248 ];
249 foreach( $list as $element ) {
250 $this->buffer['options'][ $element ] = isset( $cp_options[ $element ] )? $cp_options[ $element ]:0;
251 }
252 }
253
254 /**
255 * Remove the ABSPATH from a path
256 */
257 private function shorten_path( $path ) {
258
259 return str_replace( ABSPATH, '', $path );
260 }
261
262 }
263
264 // =====================================================================
265 // EOF
266