Skip to content
/ etcdsh Public

A PHP session handler, which stores the session data in an ETCD cluster.

License

Notifications You must be signed in to change notification settings

nixn/etcdsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nixn/etcdsh

A PHP session handler, which stores the session data in an ETCD cluster and enables automatic cleaning of sessions with ETCD's lease system.

It uses the PHP session lifetime (session.gc_maxlifetime) for the data, which enables automatic cleaning of the session data after session timeout - with no interaction from the application side (like CRON jobs or the like).

Due to the nature of ETCD it is possible to have multiple web servers, which all access the same session data, so possibly session stickiness could be rethought…

Setup

Installation

etcdsh uses the Aternos gRPC ETCD client, which needs the extension php-grpc.

apt install php-grpc
composer require nixn/etcdsh

Usage

use nix\etcdsh\EtcdSessionHandler;
use Aternos\Etcd\Client as EtcdClient;

session_name('MY_SESSION_NAME'); // recommended to set, default is PHPSESSID
session_set_save_handler(new EtcdSessionHandler(new EtcdClient('localhost')));
session_save_path('sessions/'); // used as prefix in ETCD ("<name>/<id>:<lease-id>" appended)
ini_set('session.gc_probability', 0); // GC not needed with EtcdSessionHandler
ini_set('session.gc_maxlifetime', 1440); // set lifetime to your liking
session_start();

NOTE: The package name is nix\etcdsh, not nixn\etcdsh.

License

Copyright © 2023 nix https://keybase.io/nixn

Distributed under the MIT license, available in the file LICENSE.

Donations

If you like etcdsh, please consider dropping some bitcoins to 1nixn9rd4ns8h5mQX3NmUtxwffNZsbDTP.

About

A PHP session handler, which stores the session data in an ETCD cluster.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages