PHP Doku:: Liefert die aktuelle Cache-Verfallszeit - function.session-cache-expire.html

Verlauf / Chronik / History: (2) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSession-ErweiterungenSessionbehandlungSession-Funktionensession_cache_expire

Ein Service von Reinhard Neidl - Webprogrammierung.

Session-Funktionen

<<Session-Funktionen

session_cache_limiter>>

session_cache_expire

(PHP 4 >= 4.2.0, PHP 5)

session_cache_expireLiefert die aktuelle Cache-Verfallszeit

Beschreibung

int session_cache_expire ([ string $new_cache_expire ] )

session_cache_expire() gibt die aktuelle Einstellung von session.cache_expire zurück.

Die Cache-Verfallszeit wird zu Beginn einer Anfrage auf den standardmäßigen Wert von 180, der in session.cache_expire gespeichert ist, zurückgesetzt. Folglich müssen Sie session_cache_expire() bei jeder Anfrage (und vor dem Aufruf von session_start()) aufrufen.

Parameter-Liste

new_cache_expire

Wenn new_cache_expire angegeben wurde, wird die aktuelle cache_expire durch new_cache_expire ersetzt.

Hinweis: Das Setzen von new_cache_expire bewirkt nur dann etwas, wenn session.cache_limiter auf einen anderen Wert als nocache gesetzt ist.

Rückgabewerte

Gibt die aktuelle Einstellung von session.cache_expire zurück. Der zurückgegebene Wert wird in Minuten angegeben und ist standardmäßig auf 180 gesetzt.

Beispiele

Beispiel #1 session_cache_expire() Beispiel

<?php

/* setzen der Cacheverwaltung auf 'private' */

session_cache_limiter('private');
$cache_limiter session_cache_limiter();

/* setzen der Cache-Verfallszeit auf 30 Minuten */
session_cache_expire(30);
$cache_expire session_cache_expire();

/* starten der Session */

session_start();

echo 
"Die Cacheverwaltung ist jetzt auf $cache_limiter gesetzt<br />";
echo 
"Die Session wird für $cache_expire Minuten im Cache gespeichert";
?>

Siehe auch


6 BenutzerBeiträge:
- Beiträge aktualisieren...
Anonymous
20.02.2008 17:50
The manual probably doesn't stress this enough:

** This has nothing to do with lifetime of a session **

Whatever you set this setting to, it won't change how long sessions live on your server.

This only changes HTTP cache expiration time (Expires: and Cache-Control: max-age headers), which advise browser for how long it can keep pages cached in user's cache without having to reload them from the server.
info at ericbontenbal dot nl
8.08.2006 21:34
you can change the max lifetime for a session with the function ini_set().

<?php
ini_set
("session.gc_maxlifetime", "18000");
?>
This will set the max lifetime of the script to 5 hours. You have to use this in every script that you want to change the default lifetime for.

if you want to know the lifetime of your current script, you can use:

<?php
echo ini_get("session.gc_maxlifetime");
?>
lukasz at pilorz dot net
21.11.2005 2:49
I had a problem with session expiration time on a server where I didn't have access to php.ini. My solution was to use session_save_path with my own dir.
djmaze (AT) dragonflycms
23.09.2005 16:21
After recieving a "bogus" mark on a bug report i've tried to find out the differences between cache_expire and what was causing a session delete after 24 minutes.

cache_expire is used for cached session pages and has nothing to do with the session data

The garbage collector controls the session data and destroys sessions which are older then 1440 seconds (24 minutes) by default.

So to keep a session alive longer then 24 minutes (for example when a visitor tries to POST a huge message that took him 1 hour to type), you must modify the session.gc_maxlifetime thru ini_set()

Somehow i couldn't find anything in the PHP documentation regarding this and due to that me (and i think many others) got the wrong ideas regarding PHP sessions.
A few examples to fix session timeout are already posted below but in my opinion they all missed session.gc_maxlifetime
lance_rushing at hotmail dot com
17.06.2005 23:47
I've encountered the same problem of loosing focus when using IE and a javascript window.location.refresh/replace().

After fusing around I found that a <meta http-equiv="refresh" content="600"> works without move the focus on the parent frame's form.  The down side is loading up the browser history and an annoying 'click' in IE on the page load.
bermi·ferrer·[·at·]·akelos·[NO·SPAM]·com
3.06.2004 10:11
Hello,
Some of my customers asked me for a solution form their session not to expire when filling large forms. Sometimes it takes them more than 2 hours to submit (phone, desk customers...).
I know I could have forced an ilayer to be refreshed dynamically and then include PHP code using session_cache_expire() function, but this refreshing a page changes the form focus. So I found this the only solution for them not to loose focus over their form element.

You can make a session not to expire by using this code.
Its a mixture of PHP and JavaScript and can be used on the same page were your code goes or it can be called using an ilayer/iframe from your page.

I know this is not the best practice, but in some cases were user has no control over server globals and security is not important this can help.

Here is the code.

<?

//First of all we prevent browsers from caching the image
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

//This piece of code returns a blank gif
if($_GET[img] > 0){
   
header('Content-Type: image/gif');
   
header("Content-Disposition: inline; filename=".time().".gif");
    echo
base64_decode(str_replace("\n","","
R0lGODlhAQABAPcAAAAAAAAAQAAAgAAA/
wAgAAAgQAAggAAg/wBAAABAQABAgABA/
wBgAABgQABggABg/wCAAACAQACAgACA/
wCgAACgQACggACg/wDAAADAQADAgADA/
wD/AAD/QAD/gAD//yAAACAAQCAAgCAA/
yAgACAgQCAggCAg/yBAACBAQCBAgCBA/
yBgACBgQCBggCBg/yCAACCAQCCAgCCA/
yCgACCgQCCggCCg/yDAACDAQCDAgCDA/
yD/ACD/QCD/gCD//0AAAEAAQEAAgEAA/
0AgAEAgQEAggEAg/0BAAEBAQEBAgEBA/
0BgAEBgQEBggEBg/0CAAECAQECAgECA/
0CgAECgQECggECg/0DAAEDAQEDAgEDA/
0D/AED/QED/gED//2AAAGAAQGAAgGAA/
2AgAGAgQGAggGAg/2BAAGBAQGBAgGBA/
2BgAGBgQGBggGBg/2CAAGCAQGCAgGCA/
2CgAGCgQGCggGCg/2DAAGDAQGDAgGDA/
2D/AGD/QGD/gGD//4AAAIAAQIAAgIAA/
4AgAIAgQIAggIAg/4BAAIBAQIBAgIBA/
4BgAIBgQIBggIBg/4CAAICAQICAgICA/
4CgAICgQICggICg/4DAAIDAQIDAgIDA/
4D/AID/QID/gID//6AAAKAAQKAAgKAA/
6AgAKAgQKAggKAg/6BAAKBAQKBAgKBA/
6BgAKBgQKBggKBg/6CAAKCAQKCAgKCA/
6CgAKCgQKCggKCg/6DAAKDAQKDAgKDA/
6D/AKD/QKD/gKD//8AAAMAAQMAAgMAA/
8AgAMAgQMAggMAg/8BAAMBAQMBAgMBA/
8BgAMBgQMBggMBg/8CAAMCAQMCAgMCA/
8CgAMCgQMCggMCg/8DAAMDAQMDAgMDA/
8D/AMD/QMD/gMD///8AAP8AQP8AgP8A/
/8gAP8gQP8ggP8g//9AAP9AQP9AgP9A/
/9gAP9gQP9ggP9g//+AAP+AQP+AgP+A/
/+gAP+gQP+ggP+g///AAP/AQP/AgP/A/
///AP//QP//gP///yH5BAEAAP8ALAAAA
AABAAEAAAgEAP8FBAA7"
));
    exit;
}

?>

<!-- HERE YOU CAN INSERT THE HTML OR PHP CODE -->

<img name="keepUpdated" src="<?=$_SELF?>?img=999">
<script language="Javascript">
<!--
var updateEvery = 30;//Seconds
function keepUpdated() {
    timer=setTimeout("updateImage()",1000*updateEvery)
}
function updateImage() {
    var randNum = Math.floor(Math.random()*999);
    document.images.keepUpdated.src ="<?=$_SELF?>?img="+randNum;
    keepUpdated();
}
keepUpdated();
//-->
</script>

I hope this can be helpful for someone.

Bermi Ferrer



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)