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