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

Breadcrumb

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

function PdoSessionHandler::beginTransaction

Helper method to begin a transaction.

Since SQLite does not support row level locks, we have to acquire a reserved lock on the database immediately. Because of https://bugs.php.net/42766 we have to create such a transaction manually which also means we cannot use PDO::commit or PDO::rollback or PDO::inTransaction for SQLite.

Also MySQLs default isolation, REPEATABLE READ, causes deadlock for different sessions due to https://percona.com/blog/2013/12/12/one-more-innodb-gap-lock-to-avoid/ . So we change it to READ COMMITTED.

2 calls to PdoSessionHandler::beginTransaction()
PdoSessionHandler::doRead in vendor/symfony/http-foundation/Session/Storage/Handler/PdoSessionHandler.php
Reads the session data in respect to the different locking strategies.
PdoSessionHandler::getSelectSql in vendor/symfony/http-foundation/Session/Storage/Handler/PdoSessionHandler.php
Return a locking or nonlocking SQL query to read session information.

File

vendor/symfony/http-foundation/Session/Storage/Handler/PdoSessionHandler.php, line 555

Class

PdoSessionHandler
Session handler using a PDO connection to read and write data.

Namespace

Symfony\Component\HttpFoundation\Session\Storage\Handler

Code

private function beginTransaction() : void {
    if (!$this->inTransaction) {
        if ('sqlite' === $this->driver) {
            $this->pdo
                ->exec('BEGIN IMMEDIATE TRANSACTION');
        }
        else {
            if ('mysql' === $this->driver) {
                $this->pdo
                    ->exec('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
            }
            $this->pdo
                ->beginTransaction();
        }
        $this->inTransaction = true;
    }
}

API Navigation

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