定制 geekjob/expressjs-php-session-handler 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

geekjob/expressjs-php-session-handler

Composer 安装命令:

composer require geekjob/expressjs-php-session-handler

包简介

Session handler compatible with Node.js express-session handler

README 文档

README

This library is meant to work as a Session Handler for PHP that is compatible with express-session.

This library writed for SOA (Service-oriented architecture) projects for sharing session between a Node.js application and services writed on PHP.

Requirements

  • PHP: 8.1 or greater
  • phpredis
  • php_serialize Standart PHP Serialize Handler.

This library now created for using express-session with the connect-redis Session Store as common session store.

Installation

Install Redis

You can install it using pecl install redis

In Docker file:

FROM php:fpm
...
RUN pecl install redis && docker-php-ext-enable redis

Composer

Just run to get the package from packagist.org:

composer require geekjob/expressjs-php-session-handler

Setup and Usage

Configure Node.js application

app.use(session({
	name: 'sid',
	secret: 'secret key',
	cookie: {
		// Share cookie through sub domains if you use many domains for service architecture
		domain : '.your.domain',
		maxAge : Date.now() + 60000
	},
	store: new RedisStore({
		host  : 'redis',
		port  : 6379,
		client: redis,
		prefix: 'session:',
		ttl   : 3600 // 60 min
	})
}));

Configure runtime

require_once 'vendor/autoload.php';


\GeekJOB\ExpressjsSessionHandler::register(
	name  : 'sid',
	secret: 'secret key',
	cookie: [
		'domain'  => '.your.domain', // Share cookie through sub domains
		'path'    => '/',
		'maxage'  => strtotime('+1hour')-time(), // Set maxage
	],
	store : [
		'handler' => 'redis',
		'path'    => 'tcp://127.0.0.1:6379',
		'prefix'  => 'session:',
        	'ttl'	  => 3600 // 60 min
	],
	secure: false // Set to true if signature verification is needed.
);

or use list like way for config

\GeekJOB\ExpressjsSessionHandler::register(
    [
	'name'   => 'sid',
	'secret' => 'secret key',
	'cookie' => [
		'domain'  => '.your.domain', // Share cookie through sub domains
		'path'    => '/',
		'maxage'  => strtotime('+1hour')-time(), // Set maxage
	],
	'store' => [
		'handler' => 'redis',
		'path'    => 'tcp://127.0.0.1:6379',
		'prefix'  => 'session:',
        	'ttl'	  => 3600 // 60 min
	],
	'secure' => false // Set to true if signature verification is needed.
    ]
);

Configure for production server via php.ini file

session.session_name = sid
session.save_handler = redis
session.save_path = "tcp://127.0.0.1/?prefix=session:"
session.serialize_handler = php_serialize

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
; http://php.net/session.gc-maxlifetime
; default: session.gc_maxlifetime = 1440 
; Redis Sessions use this value for setting TTL
session.gc_maxlifetime =

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
; http://php.net/session.cookie-lifetime
session.cookie_lifetime =
require_once 'vendor/autoload.php';

\GeekJOB\ExpressjsSessionHandler::register(
    secret: 'secret key',
    cookie: [
	'domain'  => '.your.domain', // Share cookie through sub domains
	'path'    => '/',
    ]
);

TODO

  • MongodDB support
  • Dragonfly support
  • Unit tests :)

统计信息

  • 总下载量: 113
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固