PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.7.4
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.7.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
← All changes | lib/class-stream.php +67 -38 1.51.7.4 View file →
@@ -1,6 +1,6 @@
1 1 <?php
2 -/*
2 +/**
3 3 +=====================================================================+
4 4 | ____ _ ____ __ _ _ |
5 5 | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ |
6 6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
@@ -6,9 +6,9 @@
6 6 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
7 7 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
8 8 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
9 9 | |
10 - | (c) Jerome Bruandet ~ https://code-profiler.com/ |
10 + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
11 11 +=====================================================================+
12 12 */
13 13
14 14 if (! defined( 'ABSPATH' ) ) { die( 'Forbidden' ); }
@@ -49,9 +49,9 @@
49 49 public static function stop() {
50 50 stream_wrapper_restore( self::$protocol );
51 51 }
52 52
53 - /*
53 + /**
54 54 * Opens file or URL
55 55 */
56 56 public function stream_open( $path, $mode, $options, &$opened_path ) {
57 57 self::$io_stats['open']++;
@@ -61,15 +61,38 @@
61 61 } else {
62 62 $this->resource = fopen( $path, $mode, $options );
63 63 }
64 64 self::start();
65 - if ( in_array( $mode, ['rb', 'rt', 'r']) && "{$path[-4]}{$path[-3]}{$path[-2]}{$path[-1]}" == '.php') {
66 - $this->script = 1;
65 +
66 + if ( version_compare( PHP_VERSION, '8.0', '<') ) {
67 + if ( in_array( $mode, ['rb', 'rt', 'r']) &&
68 + "{$path[-4]}{$path[-3]}{$path[-2]}{$path[-1]}" == '.php') {
69 +
70 + $this->script = $this->check_exclusions( $path );
71 + }
72 + } else {
73 + if ( str_ends_with( $path, '.php') && in_array( $mode, ['rb', 'rt', 'r']) ) {
74 + $this->script = $this->check_exclusions( $path );
75 + }
67 76 }
77 +
68 78 return $this->resource !== false;
69 79 }
70 80
71 - /*
81 + /**
82 + * Check file and folder exclusions.
83 + */
84 + private function check_exclusions( $path ) {
85 +
86 + foreach( CodeProfiler_Profiler::$exclusions as $item ) {
87 + if ( $item && strpos( $path, $item ) !== false ) {
88 + return;
89 + }
90 + }
91 + return 1;
92 + }
93 +
94 + /**
72 95 * Close a resource
73 96 */
74 97 public function stream_close() {
75 98 self::$io_stats['close']++;
@@ -75,9 +98,9 @@
75 98 self::$io_stats['close']++;
76 99 return fclose( $this->resource );
77 100 }
78 101
79 - /*
102 + /**
80 103 * Tests for end-of-file on a file pointer
81 104 */
82 105 public function stream_eof() {
83 106 self::$io_stats['eof']++;
@@ -83,9 +106,9 @@
83 106 self::$io_stats['eof']++;
84 107 return feof( $this->resource );
85 108 }
86 109
87 - /*
110 + /**
88 111 * Flushes the output
89 112 */
90 113 public function stream_flush() {
91 114 self::$io_stats['flush']++;
@@ -91,9 +114,9 @@
91 114 self::$io_stats['flush']++;
92 115 return fflush( $this->resource );
93 116 }
94 117
95 - /*
118 + /**
96 119 * Seeks to specific location in a stream
97 120 */
98 121 public function stream_seek( $offset, $whence = SEEK_SET ) {
99 122 self::$io_stats['seek']++;
@@ -99,9 +122,9 @@
99 122 self::$io_stats['seek']++;
100 123 return fseek( $this->resource, $offset, $whence ) === 0;
101 124 }
102 125
103 - /*
126 + /**
104 127 * Delete a file
105 128 */
106 129 public function unlink( $path ) {
107 130 self::$io_stats['unlink']++;
@@ -114,9 +137,9 @@
114 137 self::start();
115 138 return $res;
116 139 }
117 140
118 - /*
141 + /**
119 142 * Renames a file or directory
120 143 */
121 144 public function rename( $path_from, $path_to ) {
122 145 self::$io_stats['rename']++;
@@ -129,9 +152,9 @@
129 152 self::start();
130 153 return $res;
131 154 }
132 155
133 - /*
156 + /**
134 157 * Removes a directory
135 158 */
136 159 public function rmdir( $path, $options ) {
137 160 self::$io_stats['rmdir']++;
@@ -144,9 +167,9 @@
144 167 self::start();
145 168 return $res;
146 169 }
147 170
148 - /*
171 + /**
149 172 * Retrieve the underlaying resource
150 173 */
151 174 public function stream_cast( $cast_as ) {
152 175 self::$io_stats['cast']++;
@@ -152,9 +175,9 @@
152 175 self::$io_stats['cast']++;
153 176 return $this->resource;
154 177 }
155 178
156 - /*
179 + /**
157 180 * Advisory file locking
158 181 */
159 182 public function stream_lock( $operation ) {
160 183 self::$io_stats['lock']++;
@@ -163,9 +186,9 @@
163 186 }
164 187 return flock( $this->resource, $operation );
165 188 }
166 189
167 - /*
190 + /**
168 191 * Truncate stream
169 192 */
170 193 public function stream_truncate( $new_size ) {
171 194 self::$io_stats['truncate']++;
@@ -179,9 +202,9 @@
179 202 self::$io_write += $write;
180 203 return $write;
181 204 }
182 205
183 - /*
206 + /**
184 207 * Change stream options
185 208 */
186 209 public function stream_set_option( $option, $arg1, $arg2 ) {
187 210 self::$io_stats['set_option']++;
@@ -198,9 +221,9 @@
198 221 return false;
199 222 }
200 223 }
201 224
202 - /*
225 + /**
203 226 * Change stream metadata
204 227 */
205 228 public function stream_metadata( $path, $option, $value ) {
206 229 self::stop();
@@ -232,9 +255,9 @@
232 255 self::start();
233 256 return $res;
234 257 }
235 258
236 - /*
259 + /**
237 260 * Create a directory
238 261 */
239 262 public function mkdir( $path, $mode, $options ) {
240 263 self::$io_stats['mkdir']++;
@@ -247,9 +270,9 @@
247 270 self::start();
248 271 return $res;
249 272 }
250 273
251 - /*
274 + /**
252 275 * Open directory handle
253 276 */
254 277 public function dir_opendir( $path, $options ) {
255 278 self::$io_stats['opendir']++;
@@ -262,9 +285,9 @@
262 285 self::start();
263 286 return $this->resource;
264 287 }
265 288
266 - /*
289 + /**
267 290 * Close directory handle
268 291 */
269 292 public function dir_closedir() {
270 293 self::$io_stats['closedir']++;
@@ -271,9 +294,9 @@
271 294 // closedir returns no value
272 295 return closedir( $this->resource );
273 296 }
274 297
275 - /*
298 + /**
276 299 * Read entry from directory handle
277 300 */
278 301 public function dir_readdir() {
279 302 self::$io_stats['readdir']++;
@@ -279,9 +302,9 @@
279 302 self::$io_stats['readdir']++;
280 303 return readdir( $this->resource );
281 304 }
282 305
283 - /*
306 + /**
284 307 * Rewind directory handle
285 308 */
286 309 public function dir_rewinddir() {
287 310 self::$io_stats['rewinddir']++;
@@ -287,9 +310,9 @@
287 310 self::$io_stats['rewinddir']++;
288 311 return rewinddir( $this->resource );
289 312 }
290 313
291 - /*
314 + /**
292 315 * Retrieve information about a file
293 316 */
294 317 public function url_stat( $path, $flags ) {
295 318 self::$io_stats['url_stat']++;
@@ -305,32 +328,38 @@
305 328 self::start();
306 329 return $res;
307 330 }
308 331
309 - /*
332 + /**
310 333 * Read from stream & enable ticks
311 334 */
312 335 public function stream_read( $count ) {
313 336 self::$io_stats['read']++;
314 - self::stop();
315 - if ( $this->script && ftell( $this->resource ) == 0 ) {
337 + if ( $this->script ) {
338 + self::stop();
339 + if ( ftell( $this->resource ) == 0 ) {
340 + self::start();
341 + $read = fread( $this->resource, $count - CODE_PROFILER_LENGTH );
342 + self::$io_read += strlen( $read );
343 + $pos = stripos( $read, '<?php' );
344 + if ( $pos !== false ) {
345 + return substr_replace(
346 + $read,
347 + '<?php declare(ticks='. CODE_PROFILER_TICKS .');',
348 + $pos,
349 + 5
350 + );
351 + }
352 + return $read;
353 + }
316 354 self::start();
317 - $read = fread( $this->resource, $count - CODE_PROFILER_LENGTH );
318 - self::$io_read += strlen( $read );
319 - return preg_replace(
320 - '/<\?php/i',
321 - '<?php declare(ticks='. CODE_PROFILER_TICKS .');',
322 - $read,
323 - 1
324 - );
325 355 }
326 - self::start();
327 356 $read = fread( $this->resource, $count );
328 357 self::$io_read += strlen( $read );
329 358 return $read;
330 - }
359 + }
331 360
332 - /*
361 + /**
333 362 * Retrieve information about a file resource
334 363 */
335 364 public function stream_stat() {
336 365 self::$io_stats['stat']++;
@@ -341,9 +370,9 @@
341 370 }
342 371 return $res;
343 372 }
344 373
345 - /*
374 + /**
346 375 * Retrieve the current position of a stream
347 376 */
348 377 function stream_tell() {
349 378 self::$io_stats['tell']++;