12

Every time I open var/Repots in magento 2 website, I found hundreds and thousands of error files all having the same message:

a:4:{i:0;s:71:"Unable to send the cookie. Maximum number of cookies would be exceeded.";
i:1;s:12555:"#0 /home/domain/public_html/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php(116): Magento\Framework\Stdlib\Cookie\PhpCookieManager->checkAbilityToSendCookie('form_key', '........')...

I searched a lot, but I did not find a solution. The maximum number of cookies is set to 50 by default.

The problem is not happening on my browser. It mostly happens with customers using android mobile phone's browser Android Version 4.0.2 to 4.4.0.

Clearing cache or using private browsing solves the issue on the client side. However I need a server side solution. (I asked a customer to clear the cache and the problem is solved on his mobile).

7
  • How many cookies are set? Are all of them necessary?
    – Imanuel
    Sep 18, 2017 at 10:49
  • actually I don't know. It is created automatically by the magento framework. Sep 18, 2017 at 10:52
  • It is not happening in my browser. It mostly happens with customers using android 4.0.2 to 4.4.0 mobile browsers. Sep 18, 2017 at 10:54
  • which magento version are you using? Sep 19, 2017 at 12:35
  • 1
    I contacted Magento support since I have a golden support on my magento EE account. They sent me a patch which increases the number of cookies from 20 to 50. However It does not work since the maximum number of cookies allowed is already 50. So no solution yet. Mar 7, 2018 at 12:20

3 Answers 3

6

Extend in di.xml

<preference for="Magento\Framework\Stdlib\Cookie\PhpCookieManager" type="Project\Cookies\PhpCookieManager" />
<?php
namespace Project\Cookies;

class PhpCookieManager extends \Magento\Framework\Stdlib\Cookie\PhpCookieManager
{
    const MAX_NUM_COOKIES = 100;    // original 50
    const MAX_COOKIE_SIZE = 16384;  // original 4096
}
2
  • 1
    666 max number of cookies? That can't be good Feb 3, 2022 at 0:11
  • This is working fine. but better to copy file from vendor to lib directory. Dec 12, 2023 at 14:37
4

I Was able to solved this problem by increase const MAX_COOKIE_SIZE = 40960;

public_html/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php

const MAX_NUM_COOKIES = 50;
const MAX_COOKIE_SIZE = 40960;
const EXPIRE_NOW_TIME = 1;
const EXPIRE_AT_END_OF_SESSION_TIME = 0;
1

This article should help give you a better idea on the Root Cause (i.e. how/what/why) of the issue - https://mage2.pro/t/topic/84/2

Unfortunately, it doesn't look like Magento is in any hurry to fix the issue for Android OS based browsers - https://github.com/magento/magento2/issues/7931

7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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