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

Full page caching issue on multisite #4556

Closed
nobuttsalex opened this issue May 18, 2016 · 20 comments
Closed

Full page caching issue on multisite #4556

nobuttsalex opened this issue May 18, 2016 · 20 comments

Comments

@nobuttsalex
Copy link

Steps to reproduce
Most up-to-date version of the dev branch.

There seems to be crossover in the full page cache of different websites. This only started being an issue yesterday or today so I guess it was a very recent change.

Disabling full page caching fixes the issue but obviously only a temporary solution.

Expected result
Website 1 to show Homepage 1 and Website 2 to show Homepage 2

Actual result
Both Website 1 and 2 show Homepage 1

@choukalos
Copy link

Tracking internally - MAGETWO-53126

@joanhe
Copy link
Contributor

joanhe commented May 20, 2016

@nobuttsalex We cannot reproduce this issue. It will be helpful if you can provide more information, such as Built-in cache vs. Varnish, how do you configure your two website, etc. Thanks.

@dsikkema-magento
Copy link
Contributor

Also, what kind of server is used?

@nobuttsalex
Copy link
Author

Ubuntu 15.10
Apache/2.4.18
PHP 7.0.6
MySQL 5.6.28

Configured two websites with 1 store and 1 store view in each using these instructions http://devdocs.magento.com/guides/v2.0/config-guide/multi-site/ms_apache.html

Have not setup varnish, but my env.php file looks like this:

<?php
return array (
  'backend' => 
  array (
    'frontName' => 'admin_secret',
  ),
  'install' => 
  array (
    'date' => 'Mon, 04 Apr 2016 13:34:21 +0000',
  ),
  'crypt' => 
  array (
    'key' => 'secret',
  ),
  'session' => 
  array (
    'save' => 'files',
  ),
  'db' => 
  array (
    'table_prefix' => 'secret_',
    'connection' => 
    array (
      'default' => 
      array (
        'host' => 'localhost',
        'dbname' => 'magento2',
        'username' => 'root',
        'password' => 'secret',
        'active' => '1',
      ),
    ),
  ),
  'resource' => 
  array (
    'default_setup' => 
    array (
      'connection' => 'default',
    ),
  ),
  'x-frame-options' => 'SAMEORIGIN',
  'MAGE_MODE' => 'developer',
  'cache_types' => 
  array (
    'config' => 1,
    'layout' => 1,
    'block_html' => 1,
    'collections' => 1,
    'reflection' => 1,
    'db_ddl' => 1,
    'eav' => 1,
    'config_integration' => 1,
    'config_integration_api' => 1,
    'full_page' => 0,
    'translate' => 1,
    'config_webservice' => 1,
    'compiled_config' => 1,
    'customer_notification' => 0,
  ),
  'cache' => 
  array (
    'frontend' => 
    array (
      'default' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
        ),
      ),
      'page_cache' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'database' => '1',
          'compress_data' => '0',
        ),
      ),
    ),
  ),
);

@dsikkema-magento
Copy link
Contributor

Thank you for the info. There are a few options in that doc you supplied. Are you separating your two sites by different domains, or different paths on the same domain? And are you setting the run type and run code variables in different entry points, or in htaccess?

@nobuttsalex
Copy link
Author

nobuttsalex commented May 23, 2016

The two sites are on the same domain but different subdomains. And I have this code at the bottom of index.php

$params = $_SERVER;
if ($_SERVER['HTTP_HOST'] == 'secondsite.magento2.local') {
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'websitecode';
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

@dsikkema-magento
Copy link
Contributor

dsikkema-magento commented May 23, 2016

So I still need to try to reproduce this using the same multisite technique you're using, but one observation: you're only setting PARAM_RUN_TYPE to 'website' if your secondary website is used - otherwise the var isn't set so default run type value will be 'store.' I'm not positive right now whether we support that (having different run types per website), I'll dig into that - but in the meantime, if you try setting run type to website outside of the condition, does that resolve your immediate issue?

@dsikkema-magento
Copy link
Contributor

But even using that method I don't reproduce. The puzzler is that the two websites should be differentiated in the cache by their store view codes, which should be different. Could you please add this line:
\Magento\Framework\App\ObjectManager::getInstance()->get('\Psr\Log\LoggerInterface')->emergency('vary-string:' . implode(',', $this->data));

To the beginning of \Magento\Framework\App\Http\Context::getVaryString, then visit home page on the two websites so that the wrong cache result is rendered, and share the log? It will show how the page is being tagged.

@nobuttsalex
Copy link
Author

First website:
[2016-05-24 08:13:03] main.EMERGENCY: vary-string: [] []
[2016-05-24 08:13:03] main.EMERGENCY: vary-string:0,,default,GBP [] []

Second website:
[2016-05-24 08:13:06] main.EMERGENCY: vary-string: [] []
[2016-05-24 08:13:06] main.EMERGENCY: vary-string:0,,default,GBP [] []

@dsikkema-magento
Copy link
Contributor

dsikkema-magento commented May 24, 2016

It appears as though the second website is using the same store view as the first. Can you double check that you have a separate store view and separate store for the second website?

For instance, my log output for 2nd website is:
[2016-05-24 14:43:50] main.EMERGENCY: vary-string:test_store_view,USD,0, [] []
But if I used the same store view for both sites, I'd see what you see: "default" in both.

@nobuttsalex
Copy link
Author

Each has it's own website, store and store view. They also have different themes and different categories/products and with full page cache disabled everything works as it should. I'm now on 2.1.0-rc1. In earlier versions on the dev branch my setup worked perfectly with full page cache enabled.

@nobuttsalex
Copy link
Author

Something I'll point out which may help replicate the problem is new sessions are more likely to load the wrong homepage. If a session has seen the correct homepage it will continue to however many times you refresh but if you were to clear your cookies you would probably get the wrong one again.

@dsikkema-magento
Copy link
Contributor

Ok, I was able to reproduce the problem. We'll look into it.

@KrystynaKabannyk
Copy link

Hello @nobuttsalex, this issue has been fixed in the 2.1.0 Release, that's why I'm closing it. If you any questions or additional information regarding the issue feel free to reopen it or create a new one.

@pantaoran
Copy link

I think I'm having this or a very similar issue on Magento 2.1.0.

We show a different store and theme based on the client's user agent. We set the store in pub/index.php according to the user agent, and then configure different themes for those stores.
(When I say "store" I mean the middle one of these three concepts such as named in Magento: "website", "store", "store view")

Now when I turn on the built-in full page cache, the first page visit seems to determine the theme that I will see. So if I use Firefox with one user agent, it loads theme A, but then when I load the store in Chrome with Device Mode for a mobile user agent, I will still see theme A, but I expect to see theme B.

After clearing the cache, the correct theme is loaded only on the first load. When I disable full page cache, the correct one is loaded every time.

@alevelo01
Copy link

This issue is happening again in the version 2.1.11, everything was ok until the version 2.1.10, when we update to 2.1.11, my multiple sites are not loading correctly when the full_page cache is enabled, is always loading the default store

@alevelo01
Copy link

If you force the cookie store to the correct storeviewcode it will load right the second request the first one always load the default store, even if you create the cookie on the index before all the magento magic happens

@harrywutech
Copy link

harrywutech commented Jan 6, 2019

we have the same issue as alevelo mentioned, how can we solve it? and our version is 2.2.7 Thank you

@amenk
Copy link
Contributor

amenk commented Jan 6, 2019

@hanxiangwu check if this PR works: #18624

magento-cicd2 pushed a commit that referenced this issue Oct 8, 2019
[Owls] MC-18009: Disabled Products Do Not Appear in Search Results of Link Attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants