Looked into this some more and came up with a possible fix. It’s a rather ugly hack but appears to get the job done in the least intrusive manner for someone unfamiliar with the code.
Namely:
\plugins\p3-profiler\classes\class.streamwrapper.php
line 14, changed this:
define('STREAM_WRAPPER_INJECTION_STRING', '<?php declare(ticks=1);?>');
define('STREAM_WRAPPER_INJECTION_LENGTH', 25);
to this:
define('STREAM_WRAPPER_INJECTION_STRING_ALT', '<?php declare(ticks=1,strict_types=1);?>');
define('STREAM_WRAPPER_INJECTION_STRING', '<?php declare(ticks=1); ?>'); //add spaces to match
define('STREAM_WRAPPER_INJECTION_LENGTH', 40);
and at line 119, changed this:
return $this->doWrapper(function () use ($count) {
$result = '';
if (ftell($this->handle) == 0 && $this->is_php_file) {
$result = STREAM_WRAPPER_INJECTION_STRING;
$count -= STREAM_WRAPPER_INJECTION_LENGTH;
}
return $result . fread($this->handle, $count);
});
to this:
return $this->doWrapper(function () use ($count) {
$result = '';
$wrap_it = false;
if (ftell($this->handle) == 0 && $this->is_php_file) {
$count -= STREAM_WRAPPER_INJECTION_LENGTH;
$wrap_it = true;
}
$file = fread($this->handle, $count);
// discern injection string type to use
if ($wrap_it) {
// look for statement: "declare(strict_types=1);"
$pattern = '/declare\s*+\(\s*+strict_types\s*+\=\s*+1\s*+\)\s*+;/i';
if (preg_match($pattern, $file, $matches)) {
// replace statement with same amount of spaces, to keep file stream the same size
$replace_with = str_repeat(' ', strlen($matches[0]));
//$file = preg_replace($pattern, $replace_with, $file, 1);
$file = str_replace($matches[0], $replace_with, $file);
// use alternate injection string
$result = STREAM_WRAPPER_INJECTION_STRING_ALT;
} else {
// use default injection string
$result = STREAM_WRAPPER_INJECTION_STRING;
}
}
return $result . $file;
});
The bolted on code above appears to fix the reported issue, but the next show-stopper is multiple memory allocation errors that happen specifically in the lines below when doing an Auto Scan
:
PHP Fatal error: Out of memory (allocated 138412032) (tried to allocate 6291464 bytes) in \plugins\p3-profiler\classes\class.p3-profiler.php on line 278
PHP Fatal error: Out of memory (allocated 161480704) (tried to allocate 4096 bytes) in \plugins\p3-profiler\classes\class.p3-profiler.php on line 306
Have a rather heavy WC site with 76 plugins active and I’m doing the tests only on WAMP atm. Tried tweaking various memory params in WP and PHP with mixed results. More times than not had to stop tests with ?P3_SHUTOFF=1
.
Hope for advise. Thanks.