Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NativeSessionStorage.php

function NativeSessionStorage::setSaveHandler

Registers session save handler as a PHP session handler.

To use internal PHP session save handlers, override this method using ini_set with session.save_handler and session.save_path e.g.

ini_set('session.save_handler', 'files'); ini_set('session.save_path', '/tmp');

or pass in a \SessionHandler instance which configures session.save_handler in the constructor, for a template see NativeFileSessionHandler.

Throws

\InvalidArgumentException

See also

https://php.net/session-set-save-handler

https://php.net/sessionhandlerinterface

https://php.net/sessionhandler

2 calls to NativeSessionStorage::setSaveHandler()
NativeSessionStorage::__construct in vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php
Depending on how you want the storage driver to behave you probably want to override this constructor entirely.
PhpBridgeSessionStorage::__construct in vendor/symfony/http-foundation/Session/Storage/PhpBridgeSessionStorage.php
Depending on how you want the storage driver to behave you probably want to override this constructor entirely.

File

vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php, line 364

Class

NativeSessionStorage
This provides a base class for session attribute storage.

Namespace

Symfony\Component\HttpFoundation\Session\Storage

Code

public function setSaveHandler(AbstractProxy|\SessionHandlerInterface|null $saveHandler) : void {
    // Wrap $saveHandler in proxy and prevent double wrapping of proxy
    if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
        $saveHandler = new SessionHandlerProxy($saveHandler);
    }
    elseif (!$saveHandler instanceof AbstractProxy) {
        $saveHandler = new SessionHandlerProxy(new StrictSessionHandler(new \SessionHandler()));
    }
    $this->saveHandler = $saveHandler;
    if (headers_sent() || \PHP_SESSION_ACTIVE === session_status()) {
        return;
    }
    if ($this->saveHandler instanceof SessionHandlerProxy) {
        session_set_save_handler($this->saveHandler, false);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal