We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33968
    • 863 Posts
    I have a recently launched site with fairly low traffic at the moment but wondered why the session table had grown to over 24,000 records so quickly. Session lifetime is set to 7 days and it is clearing out correctly (I might reduce this).

    As this modx install serves multiple domains in a 'white label' arrangement, I have a plugin that fires on OnHandleRequest which redirects to a different start page depending on the current domain. This is done in the plugin using $modx->sendRedirect().

    All works fine, except I've noticed it is generating two session entries in this case - one (empty) on first load and then another for the redirected page.

    Is there a way around this? It doesn't appear to be affecting site performance but I obviously don't want a table full of unused session entries, especially when traffic increases...

    Luke
    • The only way around this is to start the session for the requested domain. This means you have to handle this before the context is initialized, e.g. by having separate index.php's serving different virtual hosts, or by editing the index.php and initializing the appropriate context based on the HTTP_HOST that is being requested.

      Otherwise, you have to start the session for the first context you initialize, then another when you redirect in the plugin.
        • 33968
        • 863 Posts
        Hi Jason - thanks for the explanation, I thought that might be the case. I'll look into modifying index.php as my plugin code will almost drop straight in, although I'm never keen to go down that path.

        Cheers, Luke
        • Quote from: okyanet at Jan 05, 2012, 01:51 PM
          Hi Jason - thanks for the explanation, I thought that might be the case. I'll look into modifying index.php as my plugin code will almost drop straight in, although I'm never keen to go down that path.
          If it makes you feel better, we're going to be making the gateway files (index.php) much more configurable/flexible in the future anyway; I wouldn't worry about making these changes, since they are really necessary to configure a truly scalable site using Contexts in this way.

          There are rarely if ever any changes to the main index.php, and you can easily compare your customized one (or your alternative gateways serving additional virtual hosting directories) if changes are made. If you are worried about overwriting and losing your changes, just keep a copy of it with a different name around in case you forget about it when you do upgrade.
            • 33968
            • 863 Posts
            Yes that does make me feel better and I'm glad to know I'm on the right track. Thanks!