[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/system/sessiongc/ -> sessiongc.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  System.sessiongc
   6   *
   7   * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9  
  10   * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
  11   */
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Plugin\CMSPlugin;
  16  use Joomla\CMS\Session\MetadataManager;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Garbage collection handler for session related data
  24   *
  25   * @since  3.8.6
  26   */
  27  class PlgSystemSessionGc extends CMSPlugin
  28  {
  29      /**
  30       * Application object
  31       *
  32       * @var    CMSApplication
  33       * @since  3.8.6
  34       */
  35      protected $app;
  36  
  37      /**
  38       * Database driver
  39       *
  40       * @var    \Joomla\Database\DatabaseDriver
  41       * @since  3.8.6
  42       */
  43      protected $db;
  44  
  45      /**
  46       * Runs after the HTTP response has been sent to the client and performs garbage collection tasks
  47       *
  48       * @return  void
  49       *
  50       * @since   3.8.6
  51       */
  52      public function onAfterRespond()
  53      {
  54          if ($this->params->get('enable_session_gc', 1)) {
  55              $probability = $this->params->get('gc_probability', 1);
  56              $divisor     = $this->params->get('gc_divisor', 100);
  57  
  58              $random = $divisor * lcg_value();
  59  
  60              if ($probability > 0 && $random < $probability) {
  61                  $this->app->getSession()->gc();
  62              }
  63          }
  64  
  65          if ($this->app->get('session_handler', 'none') !== 'database' && $this->params->get('enable_session_metadata_gc', 1)) {
  66              $probability = $this->params->get('gc_probability', 1);
  67              $divisor     = $this->params->get('gc_divisor', 100);
  68  
  69              $random = $divisor * lcg_value();
  70  
  71              if ($probability > 0 && $random < $probability) {
  72                  /** @var MetadataManager $metadataManager */
  73                  $metadataManager = Factory::getContainer()->get(MetadataManager::class);
  74                  $metadataManager->deletePriorTo(time() - $this->app->getSession()->getExpire());
  75              }
  76          }
  77      }
  78  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer