Your Location is: Home > Php

Turning on PageCache in yii2 produces strange encoding problem

From: Yaren View: 3540 Marco 

Question

I have a web portal that I want to add PageCache to. When Activating it, a strange coding appears and after debugging for a while I don't understand the reason since in other projects developed in Yii2 the PageCache works correctly.

[
    'class' => 'yii\filters\PageCache',
    'only' => ['index'],
    'duration' => 300,
    'enabled'=>true,
    'variations' => [
        \Yii::$app->language,
    ],
    'dependency' => [
        'class' => 'yii\caching\DbDependency',
        'sql' => 'SELECT COUNT(*) FROM item',
    ],
],

Web config

$config = [
    'id' => 'my-web',
    'language'=>'en',
    'name'=>'My Web',
    'basePath' => dirname(__DIR__),
    'defaultRoute' => 'site/index',
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        'request' => [
            'cookieValidationKey' => 'XXXXXXXXXXXXXX',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_cookiename', 'httpOnly' => true],
        ],
        'session' => [
            'name' => 'session-identifier',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
    ],
    'params' => $params,
];
  • Ubuntu: Ubuntu 16.04.2 LTS
  • Mysql: 5.7.18-0ubuntu0.16.04.1 (Ubuntu)
  • php: 7.0.18

Cache content snippet

^_<8b>^H^@^@^@^@^@^@^Cí=ÛvÛ6¶ïý
X<9d><99>$§¦Dêfɱ<9d>ºN<9c>fN.<9e>ÆM<93>^V^VDB^Rl<92>`  Ò<96>ÓéÇôq^^æá¬y<9b><97>®ÕüØÙ^@x'%Q<8a>SÛ­<95>^UY$.^[ØØwÜv6^^¾88~sô^HM^CÇÞûdGüA6v'»^MÂ^[{<9f> øìL       ¶ÔOùè<90>^@#s<8a>}N<82>ÝÆ×Ç<87>Ú Ñ*¦»Ø!»<8d>3JÎ=æ^G^Md27 .ä?§V0ݵÈ^Y5<89>&^_6^[email protected]±­q^SÛd×ØD^N<9e>Q't¢^W½¦¾<89>BN|ù<8c>GðJo¤^@+!<9b>Ü^_k^^ö±<93><81>ýV¼<85><92>¥<8c>^A;%n&ã^[ûô5?^\¿èøüõÁ´£=yr|pö<90><85>m^]^?«^]q|ôz<82>ñ<81>ñTÿö^_úQçéøY<97>¾~wñ¤û^Of|^[|K<9f>^?ó<9a>¾6IçèâÕ³ÿýû^E^?F¦ôéì|w7Óê<9d><80>^F6Ù{é`?xÆΨ<8d>4ô^U^Q-6éûÿ¸( öû^?<8d><99>Ë8rÞÿ^GÒ      ßD¾Ìà#z4e.<81>^R/^A^_^NvM¼ÓRõ¥õÛÔ=<85>^B6t^Q»Ì¥<80>º^F<9a>úd¼Û<98>^F<81>·Ýj^YÃvÓè^O<9a><9d>NÓÐ[<8d>ʲØ^N<88>ïâ<80>¨²    i,¬     Í!^G^\^FSægð<9c>ö~ÙxZ<84><9b>>õ^Bʲã^Tã£^BY<88>Ǩi&xe.r<98>J^M^D^Y^E<80>RA<9e>ï^?       äË^Kä<84>æ<94>A^]¿ð&:^@(Ø<81>*^A^\^Bê^C<8a>¥^LY$^Z^E5Ldæù<84>ó^XF<4<8d>j^DL^X<9b>ØDã4 Ú^Yñé^XF¥Ð¥Ù<9b>Wçmã^[»ëôÂCþhöôHcìø^_o»Ý§£·§^G§Ó·xüÎÖ^O¼Çæ\<;ü^LÛÔ<82>QkêF¦î~ça»ß3<8c>n{h|qð¨×ë^_^ZíÃîðàáaGï^Z<83>\<85><85><9a>=<9f>yÄ^O.v^[l²m3Á<98><99><9a ......

I added several screenshots

enter image description here

What can be the reason for this behavior?

Best answer