phpgt/session 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

phpgt/session

Composer 安装命令:

composer require phpgt/session

包简介

Encapsulated user sessions.

README 文档

README

This library is a simple object oriented alternative to the $_SESSION superglobal allowing application code to be passed encapsulated SessionStore objects, so areas of code can have access to their own Session area without having full read-write access to all session variables.

Sessions are addressed using dot notation, allowing for handling categories of session data. This is particularly useful when dealing with user authentication, for example.

Build status Code quality Code coverage Current version PHP.GT/Session documentation

Example usage: Welcome a user by their first name or log out the user

if($session->contains("auth")) {
// Remove the *whole* auth section of the session on logout.
	if($action === "logout") {
		$session->delete("auth");
	}
	else {
// Output a variable within the auth namespace:
		$message = "Welcome back, " . $session->getString("auth.user.name");
	}
}
else {
// Pass the "auth" store to a class, so it 
// can't read/write to other session variables:
	AuthenticationSystem::beginLogin($session->getStore("auth"));
}

Redis session storage

This package now includes GT\Session\RedisHandler for shared session storage. It works with Redis-compatible backends such as Redis and Valkey, and is intended for deployments where application nodes are disposable and session state needs to survive traffic moving between servers.

RedisHandler expects save_path to be a DSN rather than a filesystem path. It uses the phpredis extension at runtime.

Example production config:

[session]
handler=GT\Session\RedisHandler
save_path=rediss://default:secret@example-redis.internal:25061/0?prefix=GT:&ttl=1440
name=GT
use_cookies=true

Supported DSN forms:

  • redis://host:6379
  • redis://:password@host:6379/0
  • redis://username:password@host:6379/0
  • rediss://username:password@host:6379/0

Useful query parameters:

  • prefix: key prefix for stored sessions, defaults to <session-name>:
  • ttl: session lifetime in seconds, defaults to session.gc_maxlifetime
  • timeout: connection timeout in seconds
  • read_timeout: socket read timeout in seconds
  • persistent=1: enable persistent connections
  • persistent_id: optional persistent connection pool id
  • verify_peer=0 / verify_peer_name=0: optional TLS verification flags

Proudly sponsored by

JetBrains Open Source sponsorship program

JetBrains logo.

phpgt/session 适用场景与选型建议

phpgt/session 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.92k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 phpgt/session 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 phpgt/session 我们能提供哪些服务?
定制开发 / 二次开发

基于 phpgt/session 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 9
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-06