记录一段QQ关于 UNIGUI 的Session 时间设定
记录一段QQ关于 UNIGUI 的Session 时间设定,来自[台中]cmj(31365722):
1.UniGUI的Session就是UniMainModule。
2.SessionTimeOut預設600000 即600秒,其代表 Session在完全沒有動作下只能存
活600秒,所謂動作是鍵盤、滑鼠、事件觸發,。
3.SessionTimeOut 600秒,若Session在600秒死了,系統也要等該Session滿600
秒後才會回收,可能造成無用的Session占用系統資源一段時間。
4.SessionTimeout設為5秒鐘,Session 5秒鐘就快速回收,不會有無用Session大
量存在問題,但存活時間只有5秒鐘。
5.以上兩點都有問題,解決方式是加一個次數,即5秒x120次數=600秒,再利用
Session展延機制,這樣Session可以存活600秒,沒用的Session也在5秒鐘
快速回收。
[UNIGui Session回收流程]
SessionTimeout時間到→TUniMainModule.UniGUIMainModuleSessionTimeout事件→是否展延?
否: TUniMainModule.UniGUIMainModuleDestroy,回收.
是: 繼續存活一個SessionTimeout時間
[UniServerModule]
屬性: SessionTimeout: Session存在時間(完全沒有動作之下),不可改變.
只能在UniGUIServerModuleBeforeInit事件設定
加入變數
public
SessionTimeCount:Integer; //SessionTimeout 存活次數
LastSessionCreateTime:TDateTime; //最後Session建立時間
procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender:
TObject);
begin
Self.SessionTimeout:=5*1000; //存活一次時間5秒
Self.SessionTimeCount:=60; //60次,總存活時間=5x60=300秒
Self.LastSessionCreateTime:=now; //第一個Session建立時間
end;
[UniMainModule]
屬性: TerminateOnBrowserClose 一定設為True;
加入變數
public
SessionTimeCount: Integer; //Session存活次數,一次為一SessionTimeOut
IsALive:Boolean; //Session是否活著
procedure TUniMainModule.UniGUIMainModuleBrowserClose(Sender: TObject);
begin
Self.SessionTimeCount:=0; //Session展延次數取消,準備回收
end;
procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
var dt:TDateTime; //Session建立時間
DSec:integer; //Session與前一個Session建立的時間差
begin
dt:=Now;
DSec:=SecondsBetween(Dt , UniServerModule.LastSessionCreateTime);
//兩個Session建立間隔需大於2秒,以防止2秒內大量建Session
if (DSec<=2) then UniSession.Terminate();
//記錄最後一個Session建立時間
UniServerModule.LastSessionCreateTime:=Dt;
Self.SessionTimeCount:=UniServerModule.SessionTimeCount; //存活次數
if UniServerModule.SessionManager.Sessions.SessionList.Count>500 then
//最多500 Session建立
begin
//UniServerModule.MyLog.Add('Session數>500');
UniSession.Terminate();
end;
end;
procedure TUniMainModule.UniGUIMainModuleHandleRequest(ASession:
TObject;var Handled: Boolean);
var Session:TUniGUISession;
begin
Self.SessionTimeCount:=UniServerModule.SessionTimeCount;
//Keyboard,mouse,or其他動作重設SessionTimeout次數
end;
procedure TUniMainModule.UniGUIMainModuleSessionTimeout(ASession:
TObject; var ExtendTimeOut: Integer);
var Session:TUniGUISession;
begin
//Session:= TUniGUISession(ASession);
//Session已死,未曾執行UniLoginFormAfterShow或UniFormCreate事件
if not Self.IsALive then Self.SessionTimeCount:=0;
//存活次數大於0時就展延
if (Self.SessionTimeCount>0) then
begin
ExtendTimeOut:=UniServerModule.SessionTimeout
end
else
UniSession.Terminate(); //立即回收Session
//展延次數減一次
Self.SessionTimeCount:=Self.SessionTimeCount-1;
end;
[LoginForm]
若沒有LoginForm改為MainForm的AfterShow事件
procedure TLoginForm.UniLoginFormAfterShow(Sender: TObject);
begin
//在瀏覽器連續F5或重新整理5次,則產生5個Session,前4個Session是死
//的不會執行本事件
TUniMainModule(UniSession.UniMainModule).IsALive:=True;
end;
[MainForm]
顯示所有Session
拖入三件控件,一個TuniListBox Name=LbSession,
一個TuniButton Name=UniButton3 Caption=Session List
一個TuniButton Name=UniButton2 Caption=Clear
procedure TMainForm.UniFormAfterShow(Sender: TObject);
begin
//在瀏覽器連續F5 5次,則產生5個Session,前4個Session是死的,不會執行
//本事件
TUniMainModule(UniSession.UniMainModule).IsALive:=True;
end;
procedure TMainForm.UniButton3Click(Sender: TObject);
var UserList:TList; //登入Session List
i:integer;
Session:TUniGUISession;
m:TUniMainModule;
begin
UserList:=UniServerModule.SessionManager.Sessions.SessionList;
for i:=0 to UserList.Count-1 do
begin
Session:=TUniGUISession(Userlist[i]);
m:=TUniMainModule(Session.UniMainModule);
Self.LbSession.Items.Add(inttostr(i)+': '+
Session.SessionId +' , '+
inttostr(m.SessionTimeCount)+',Is Alive='+
GetEnumName( TypeInfo(Boolean) , Ord(m.IsALive))
);
end;
Self.LbSession.Items.Add('--------------------------------------');
end;
procedure TMainForm.UniButton2Click(Sender: TObject);
begin
Self.LbSession.Clear;
end;
[測試]
開兩個瀏覽器
瀏覽器1 監看Session
瀏覽器2 登入後快速重整多次,以模擬大量產生Session
改為
5秒x120次,Session死了,5秒就剔除
也可以改
3秒x200次,
记录一段QQ关于 UNIGUI 的Session 时间设定的更多相关文章
- 记录这段时间java编程的小知识点
记录这段时间java编程的小知识点 eclipse项目导入中文乱码 eclipse左侧目录结构变动 eclipse代码段左右移动 按tal键,是整体右移. 按shift table 同时按,是整体左 ...
- 为QNetworkAccessManager添加超时提醒(自己记录一段时间里的下载字节数,用定时器去定期检测,从而判断是否超时)
在做更新,在测试异常的时候,在下载过程中,发现如果直接系统禁用了网络,会报错误,可以捕获.但是如果是第三方软件限制程序联网,问题来了. 程序会一直在那里等待,没有异常,也不发送QNetworkAcce ...
- spring boot 延长 Session 时间
1.查看session时间 默认1800s 通过request.getSession().getMaxInactiveInterval()可以查看你的session时间 2.延长session ...
- unigui的session【1】
目前是1394. 明白session如何使用管理,看demo Session List和SessionTimeout unit Main; interface uses Windows, Messag ...
- 安卓手机端微信网页浏览记录清理debugx5.qq.com
最近我们环境从复)星(云切换到阿里云.早上地铁路上就有小伙伴@,一阵搜索.找的如下的方法. 记录一下: 目前只支持安卓手机的微信内置浏览器清理. 由腾讯提供的网址http://debugx5.qq.c ...
- Yocto开发笔记之《错误记录》(QQ交流群:519230208)
QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 ============================================== 提问: 1. 怎样修改linu ...
- matlab中,计算,记录,程序运行,起始,结束 时间,间隔 &matlab中 tic,toc函数的用法
Tic和toc函数可以计算运行一段时间的代码. 例如: clc tic d=zeros(1,10000); for i=1:10000 d(i)=i; end toc tic c=1; for i=1 ...
- 用python悄悄记录了室友的抖音在线时间
今天给大家分享一篇有趣的文章,灵感来自于前几天与室友的聊天,他告诉我抖音可以实时显示人的在线情况,如下图: 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在 ...
- cookie+session,会话时间设定
很多Web程序中第一次登录后,在一定时间内(如2个小时)再次访问同一个Web程序时就无需再次登录,而是直接进入程序的主界面(仅限于本机). 实现这个功能关键就是服务端要识别客户的身份.而用Cookie ...
随机推荐
- 虚拟机部署hadoop集群准备工作之多虚拟机设置网络信息
安装好了centos6.4(最简版)后 1,静态IP设置 查看虚拟机的网络设置信息来配置
- 【JS】JavaScript中Null和undefind区别
1.undefined:只有一个值,及特殊的undefined.在使用var声明变量但未对其初始化时,这个变量的值是undefined,简言之,undefined就是表示变量申明了但未初始化时的值. ...
- bzoj千题计划316:bzoj3173: [Tjoi2013]最长上升子序列(二分+树状数组)
https://www.lydsy.com/JudgeOnline/problem.php?id=3173 插入的数是以递增的顺序插入的 这说明如果倒过来考虑,那么从最后一个插入的开始删除,不会对以某 ...
- ArcGis Go to XY功能代码C#
IPoint point = new PointClass(); point.PutCoords(x,y); IEnvelope pEnvelope= this.m_hookHelper.Active ...
- Web服务常见问题
1. 资源无法找到 ,用58225端口发布服务的时候,没法找到 那么就换一个端口试试.http://localhost:58272/ 2. could not load file or assembl ...
- WeUI0.6.0有一个Calendar在浏览器下无法直接打开问题
主要原因是判断浏览器不支持导致.修改isPopover相关部分代码即可.
- git 完全讲解 无废话,包含在myeclipse中使用,包括解决冲突
Git 1. Git简介 1.1 git是什么 1.1.1概念 Git:git是一款开源的分布式的版本控制软件 Github:是一个基于git的面向开源及私有软件项目的托管平台 因仅支持git 作为唯 ...
- office 2016 破解教程
骤: 下载安装包——>安装(断网状态)——>下载破解工具——>破解完成 1. 下载 office2016,大家进入下面的链接进行 http://pan.baidu.com/s/1mi ...
- python 小技巧
计算时间差,时间加减运算代码 最近在学习数据预处理,碰到日期型数据不会处理,上网查了下: Q:如何方便的计算两个时间的差,如两个时间相差几天,几小时等A:使用datetime模块可以很方便的解决这个问 ...
- SQL 查看表字段及说明
select A.comments,A.column_name,B.DATA_TYPE||'('||B.DATA_LENGTH||')' from user_col_comments A inner ...