Download the PHP package mouf/utils.session.optimistic-session-handler without Composer

On this page you can find all versions of the php package mouf/utils.session.optimistic-session-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package utils.session.optimistic-session-handler

Latest Stable Version Latest Unstable Version License Build Status

OptimisticSessionHandler

PHP file-based session handler that releases session lock quickly. Useful to speed up multiple Ajax calls on the same page.

Why do we need this session handler?

It improves performances in case of projects with multiple and long Ajax requests running. Several requests using the user session can be concurrently executed by the server since the session is not locked for a long time.

By default, PHP writes session files on the disk. When you execute session_start, the session file is opened, and a lock is put on the file. If another process tries to perform a session_start, the process will wait until the lock on the session file is released. This is a security feature of PHP (2 processes cannot modify the same session at the same time), but this is dreadful for performances, as PHP requests sharing the same session must be run sequentially.

This package offers a way around this problem. It assumes that everything is going to be alright (hence the "optimistic" name), and let several processes access the session at the same time. If two processes modify the session at the same time, it will try to merge the 2 results. If it fails to do so, it will throw an exception.

How does it work?

This session handler modifies the default behaviour of PHP session handling. Sessions are still written to disk (like PHP does by default). The session is opened and read when you call session_start() to fill the global variable $_SESSION. But the session is closed immediately after. At the end of your PHP script, the $_SESSION is compared with the old session. If the session has been modified in your script, the handler re-opens a session and compare the new session with your changes. The merged session is saved.

Note: if you use an alternative session handler (like APC or Memcache), do not use this session handler. It is designed to be used with file based sessions.

 Using the session handler

It's extremely easy to use. Just declare a new instance :

$handler = new OptimisticSessionHandler();

And save it as your default session handler :

session_set_save_handler($handler, true);

Then you can start the session as usual

session_start(['read_and_close' => true]);

Then the $_SESSION array is accessible.

You can configure rules for managing conflicts. Just add element to the class parameter $conflictRules. The possible rules are:

So you can just declare a new instance like this:

$handler = new OptimisticSessionHandler(array("key_to_override" => OptimisticSessionHandler::OVERRIDE));

Destroying the session

Warning: The session can't be destroyed by session_destroy() (It will throw an error). To destroy the session, you must empty the $_SESSION array.

$_SESSION = array();

If you want more information about this package you can go on OptimisticSessionHandler: A New Way To Think PHP Sessions


All versions of utils.session.optimistic-session-handler with dependencies

PHP Build Version
Package Version
Requires php Version >= 7.2.0
psr/log Version ~1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mouf/utils.session.optimistic-session-handler contains the following files

Loading the files please wait ....