雖然session緩存能提供網(wǎng)頁性能,但是如果不限制緩存時(shí)間崎苗,會(huì)造成服務(wù)器壓力谷徙。
1、通過<code>session_cache_limiter()</code>函數(shù)創(chuàng)建緩存揭措,應(yīng)用<code>session_save_path()</code>來設(shè)置緩存路徑胯舷,應(yīng)用<code>session_cache_expiry()</code>函數(shù)設(shè)置緩存時(shí)間。
2绊含、通過<code>session_cache_limiter()</code>函數(shù)創(chuàng)建緩存桑嘶,參數(shù)有nocache(不設(shè)置緩存)、private(私有)躬充、private nocache(私有但不過期)逃顶、public(公開的)讨便。
4、<code>session_save_path()</code>來設(shè)置或者重新配置session路徑以政。
5霸褒、<code>session_cache_expiry()</code>設(shè)置session過期時(shí)間,默認(rèn)為180分鐘盈蛮。
$path='./tmp'; //存儲(chǔ)路徑
session_save_path($path);//設(shè)置緩存路徑
session_cache_limiter('private');//緩存方式
$session_cache=session_cache_limiter();//開啟緩存
session_cache_expiry(30);//定義緩存時(shí)間
$session_expiry=session_cache_expiry();//設(shè)置緩存時(shí)間
session_start();//開啟緩存
$_SESSION['cache']=$session_cache;
$_SESSION['expiry']=$session_expiry;