Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when loading magento after inserting $_SERVER['MAGE_PROFILER'] to index.php #49

Open
Eddcapone opened this issue Feb 9, 2021 · 2 comments

Comments

@Eddcapone
Copy link

Preconditions

  1. Magento 2.4.1

Steps to reproduce

  1. Follow installation instructions

If you add $_SERVER['MAGE_PROFILER'] = [ 'drivers' => [['output' => 'MSP\DevTools\Profiler\Driver\Standard\Output\DevTools']] ]; to your index.php and pub/index.php, then you will get this error:

Warning: strlen() expects parameter 1 to be string, array given in /home/companyde/redesign.company.de/app/bootstrap.php on line 58

Warning: file_get_contents(/home/companyde/redesign.company.de/var/profiler.flag): failed to open stream: No such file or directory in /home/companyde/redesign.company.de/app/bootstrap.php on line 60
1 exception(s): Exception #0 (Exception): Warning: Cannot modify header information - headers already sent by (output started at /home/companyde/redesign.company.de/app/bootstrap.php:58) in /home/companyde/redesign.company.de/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php on line 152 Exception #0 (Exception): Warning: Cannot modify header information - headers already sent by (output started at /home/companyde/redesign.company.de/app/bootstrap.php:58) in /home/companyde/redesign.company.de/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php on line 152

Expected result

Actual result

  1. [Screenshot, logs]
@mikeastral
Copy link

mikeastral commented Feb 23, 2022

I just face the same problem when using Magento 2.4.x and Magento 2.3.7

I realized that a quick workaround, no matter what Magento version is being used, is to edit app/bootstrap.php instead on index.php and/or pub/index.php

Original

$profilerConfig = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
    ? $_SERVER['MAGE_PROFILER']
    : trim(file_get_contents(BP . '/var/profiler.flag'));

if ($profilerConfig) {
    $profilerConfig = json_decode($profilerConfig, true) ?: $profilerConfig;
}

After modification:

$profilerConfig = $_SERVER['MAGE_PROFILER'] = [ 'drivers' => [['output' => 'MSP\DevTools\Profiler\Driver\Standard\Output\DevTools']] ];

/*$profilerConfig = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
    ? $_SERVER['MAGE_PROFILER']
    : trim(file_get_contents(BP . '/var/profiler.flag'));

if ($profilerConfig) {
    $profilerConfig = json_decode($profilerConfig, true) ?: $profilerConfig;
}*/

@RobertoZeppilli
Copy link

Hi Mike, so I did the same thing, I moved the $_SERVER to app/bootstrap.php and save it in a variable as you did. But is not working. I flushed the cache, disabled Full Page Cache, upgraded the db and, enabled devtools and IP (I've added my IP) restrictions on admin page. But still is not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants