1

Please teach in order to solve the problem.

cd /vagrant
sudo php bin/magento setup:upgrade
sudo php bin/magento setup:di:compile
sudo php bin/magento setup:static-content:deploy
sudo php bin/magento setup:static-content:deploy ja_JP
sudo php bin/magento cache:flush;
sudo php bin/magento cache:clean
sudo php bin/magento indexer:reindex
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R :www-data .
sudo chmod u+x bin/magento

1 exception(s): Exception #0 (InvalidArgumentException): Unable to serialize value.

Exception #0 (InvalidArgumentException): Unable to serialize value.
#0 /vagrant/vendor/magento/framework/App/PageCache/Kernel.php(153):

Magento\Framework\Serialize\Serializer\Json->serialize(Array) #1 /vagrant/vendor/magento/module-page-cache/Model/Controller/Result/BuiltinPlugin.php(96): Magento\Framework\App\PageCache\Kernel->process(Object(Magento\Framework\App\Response\Http\Interceptor)) #2 /vagrant/vendor/magento/framework/Interception/Interceptor.php(146): Magento\PageCache\Model\Controller\Result\BuiltinPlugin->afterRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Magento\Framework\View\Result\Page\Interceptor), Object(Magento\Framework\App\Response\Http\Interceptor)) #3 /vagrant/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Response\Http\Interceptor)) #4 /vagrant/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(26): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array) #5 /vagrant/vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor)) #6 /vagrant/vendor/magento/framework/App/Bootstrap.php(257): Magento\Framework\App\Http->launch() #7 /vagrant/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor)) #8 {main}

5
  • post code that is getting the error
    – fmsthird
    Mar 5, 2019 at 8:27
  • have you cleared the caches? Mar 5, 2019 at 8:28
  • Yes, I deleted the cache. Mar 5, 2019 at 8:31
  • Please follow @Ronak Rathod's answer. It will solve your problem. Mar 5, 2019 at 8:35
  • I followed Ronak Rathod's answer, but the problem is not solved. We still need help. Mar 5, 2019 at 8:53

3 Answers 3

1

The problem is in /vendor/magento/framework/Serialize/Serializer/Json.php there is a function unserialize($string)

There is a workaround - you can check if string is serialized and then use serialize($string). Change unserialize to:

public function unserialize($string)
{
    /* Workaround: serialize first if is serialized */
    if($this->is_serialized($string))
    {
        $string = $this->serialize($string);
    }
    $result = json_decode($string, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
         throw new \InvalidArgumentException('Unable to unserialize value.');

    }
    return $result;
}

and add function to check if string is serialized:

function is_serialized($value, &$result = null)
{
    // Bit of a give away this one
    if (!is_string($value))
    {
        return false;
    }
    // Serialized false, return true. unserialize() returns false on an
    // invalid string or it could return false if the string is serialized
    // false, eliminate that possibility.
    if ($value === 'b:0;')
    {
        $result = false;
        return true;
    }
    $length = strlen($value);
    $end    = '';
    switch ($value[0])
    {
        case 's':
            if ($value[$length - 2] !== '"')
            {
                return false;
            }
        case 'b':
        case 'i':
        case 'd':
            // This looks odd but it is quicker than isset()ing
            $end .= ';';
        case 'a':
        case 'O':
            $end .= '}';
            if ($value[1] !== ':')
            {
                return false;
            }
            switch ($value[2])
            {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                    break;
                default:
                    return false;
            }
        case 'N':
            $end .= ';';
            if ($value[$length - 1] !== $end[0])
            {
                return false;
            }
            break;
        default:
            return false;
    }
    if (($result = @unserialize($value)) === false)
    {
        $result = null;
        return false;
    }
    return true;
}
1
  • error is throwed in serialize() function, not unserialize(), so your code has no effect
    – zekia
    Mar 30, 2020 at 6:28
1

Please remove var cache as sudo rm -rf var/cache var/page_cache. It works for me.

0

Please add more description when submiting a Question , when this error showed up and for what reason ?

Possible solutions:

  • Clear redis cache :

    redis-cli flushall

  • Permissions issue , need to set the umask :

Follow this link

Check this link for more info link

11
  • Could you tell me the command by example? Mar 5, 2019 at 9:01
  • What command do you want to know? Mar 5, 2019 at 9:03
  • Move to the root directory and run "echo 077 > magento_umask"? Mar 5, 2019 at 9:05
  • Better run this command : " echo 022 > magento_umask " Mar 5, 2019 at 9:19
  • I confirmed that "echo 022> magento_umask" file was created and the setting was written. I logged in to the administrator screen and confirmed the front end, but the problem was not solved. Mar 5, 2019 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.