Memory leak on CLI commands with module installed
Opened this issue · 1 comments
There seems to be some kind of hole that causes lot of memory leaking on php bin/magento CLI usage on custom scripts or even Mirasvit_ElasticSearch usage having the Mirasvit_Profiler installed on the store.
Wasted some hours of the team for debugging custom products importer, downgrading the store and plugins. We've finally figured out, that without any warning the reason of 20MB being added to memory through each loop element comes from the module-profiler 👎 :(
It is actually not a memory "leak" precisely. The profiler naturally stores information during operations. However I do agree CLI commands should not trigger the profiler...
I too wasted 3 days on this going down to PHP source build and MySql drivers check... pfff 🤬
Can be changed here I suppose to force CLI to $canEnable = false
:
$_SERVER['MAGE_PROFILER_STAT'] = new \Magento\Framework\Profiler\Driver\Standard\Stat();
$canEnable = defined('BP');
if (PHP_SAPI == 'cli') {
$canEnable = false;
// global $argv;
// if (isset($argv[1]) && substr($argv[1], 0, strlen('setup')) == 'setup') {
// $canEnable = false;
// }
}
if ($canEnable) {
\Magento\Framework\Profiler::applyConfig([
'drivers' => [
[
'output' => 'Mirasvit\Profiler\Model\Driver\Output\Html',
'stat' => $_SERVER['MAGE_PROFILER_STAT'],
],
],
], 'BP', false);
}
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Mirasvit_Profiler',
__DIR__ . '/src/Profiler'
);