session_gc Perform session data garbage collection
发表日期:2021-07-01 08:56:51 | 来源: | | 浏览(510) 分类:Session 函数
session_gc
(PHP 7 >= 7.1.0, PHP 8)
session_gc — Perform session data garbage collection
说明
session_gc() is used to perform session data GC(garbage collection). PHP does probability based session GC by default.
Probability based GC works somewhat but it has few problems. 1) Low traffic sites' session data may not be deleted within the preferred duration. 2) High traffic sites' GC may be too frequent GC. 3) GC is performed on the user's request and the user will experience a GC delay.
Therefore, it is recommended to execute GC periodically for production systems using, e.g., "cron" for UNIX-like systems. Make sure to disable probability based GC by setting session.gc_probability to 0.
参数
此函数没有参数。
返回值
session_gc() returns number of deleted session
data for success, false
for failure.
Old save handlers do not return number of deleted session data, but only success/failure flag. If this is the case, number of deleted session data became 1 regardless of actually deleted data.
范例
示例 #1 session_gc() example for task managers like cron
<?php // Note: This script should be executed by the same user of web server process.// Need active session to initialize session data storage access.session_start(); // Executes GC immediatelysession_gc(); // Clean up session ID created by session_gc()session_destroy(); ?>
示例 #2 session_gc() example for user accessible script
<?php // Note: session_gc() is recommended to be used by task manager script, but// it may be used as follows.// Used for last GC time check$gc_time = '/tmp/php_session_last_gc'; $gc_period = 1800; session_start(); // Execute GC only when GC period elapsed. // i.e. Calling session_gc() every request is waste of resources. if (file_exists($gc_time)) { if (filemtime($gc_time) < time() - $gc_period) { session_gc(); touch($gc_time); } } else { touch($gc_time); } ?>
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- session_abort Discard session array changes and finish session(0)
- session_cache_expire 返回当前缓存的到期时间(0)
- session_cache_limiter 读取/设置缓存限制器(0)
- session_commit session_write_close() 的别名(0)
- session_create_id Create new session id(0)
- session_decode 解码会话数据(0)
- session_destroy 销毁一个会话中的全部数据(0)
- session_encode 将当前会话数据编码为一个字符串(0)
- session_gc Perform session data garbage collection(0)
- session_get_cookie_params 获取会话 cookie 参数(0)
- session_id 获取/设置当前会话 ID(0)
- session_module_name 获取/设置会话模块名称(0)
- session_name 读取/设置会话名称(0)
- session_regenerate_id 使用新生成的会话 ID 更新现有会话 ID(0)
- session_register_shutdown 关闭会话(0)
- session_reset Re-initialize session array with original values(0)
- session_save_path 读取/设置当前会话的保存路径(0)
- session_set_cookie_params 设置会话 cookie 参数(0)
- session_set_save_handler 设置用户自定义会话存储函数(0)
- session_start 启动新会话或者重用现有会话(0)
- session_status 返回当前会话状态(0)
- session_unset 释放所有的会话变量(0)
- session_write_close Write session data and end session(0)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)