GithubHelp home page GithubHelp logo

felliper / mongo-session-handler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from altmetric/mongo-session-handler

0.0 2.0 0.0 164 KB

A PHP session handler backed by MongoDB

Home Page: https://packagist.org/packages/altmetric/mongo-session-handler

License: MIT License

PHP 100.00%

mongo-session-handler's Introduction

Mongo Session Handler Build Status

A PHP session handler backed by MongoDB.

Installation

$ composer require altmetric/mongo-session-handler

Usage

<?php
use Monolog\Logger; // or any other PSR-3 compliant logger
use Altmetric\MongoSessionHandler;

$sessions = $mongoClient->someDB->sessions;
$logger = new Logger;
$handler = new MongoSessionHandler($sessions, $logger);

session_set_save_handler($handler);
session_set_cookie_params(0, '/', '.example.com', false, true);
session_name('my_session_name');
session_start();

Concurrency

As MongoDB prior to 3.0 does not support document level locking, this session handler operates on a principle of Last Write Wins.

If a user of a session causes two simultaneous writes then you may end up with the following situation:

  1. Window A reads session value of ['foo' => 'bar'];
  2. Window B reads session value of ['foo' => 'bar'];
  3. Window B writes session value of ['foo' => 'baz'];
  4. Window A writes session value of ['foo' => 'quux'].

The session will now contain ['foo' => 'quux'] as it was the last successful write. This may be surprising if you're trying to increment some value in a session as it is not locked during reads and writes:

  1. Window A reads session value of ['count' => 0];
  2. Window B reads session value of ['count' => 0];
  3. Window B writes session value of ['count' => 1];
  4. Window A writes session value of ['count' => 1].

Acknowledgements

License

Copyright © 2015 Altmetric LLP

Distributed under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.