PHP 8.3.4 Released!

session_cache_expire

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

session_cache_expireObter e/ou definir a expiração do cache atual

Descrição

session_cache_expire(?int $value = null): int|false

session_cache_expire() retorna a configuração atual de session.cache_expire.

O prazo para o cache expirar é redefinido para o padrão de 180 guardado em session.cache_expire na inicialização da requisição. Então você precisa chamar session_cache_expire() para cada requesição (e antes que session_start() seja utilizada).

Parâmetros

value

Se value é informado e não null, a expiração do cache atual é modificado para value.

Nota: Definir o valor de value tem valor apenas se session.cache_limiter é definido como um valor diferente de nocache.

Valor Retornado

Retorna a configuração atual de session.cache_expire. O valor retornado deve ser lido em minutos, padrão de 180. Caso não seja possível alterar o valor, false é retornado.

Registro de Alterações

Versão Descrição
8.0.0 value é anulável agora.

Exemplos

Exemplo #1 Exemplo de session_cache_expire()

<?php

/* define o limitador de cache para 'private' */

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

/* define o prazo do cache em 30 minutos */
session_cache_expire(30);
$cache_expire = session_cache_expire();

/* inicia a sessão */

session_start();

echo
"O limitador de cache está definido agora como $cache_limiter<br />";
echo
"As sessões em cache irão expirar depois de $cache_expire minutos";
?>

Veja Também

add a note

User Contributed Notes 2 notes

up
175
Anonymous
16 years ago
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.
up
0
tuncdan dot ozdemir dot peng at gmail dot com
1 month ago
Using PHP 8.2

session_start();

$result1 = session_cache_expire( 30 ); // setter, results in Warning: Session cache expiration cannot be changed when a session is active in ...

$result2 = session_cache_expire(); // getter

var_dump( $result1, $result2 ); // prints out: int(180) int(180) [note: 180 is the default value]

Because the session was already started, cache expiration could not be changed (warning message). However, the return value is NOT false, it is still the original, unchanged value!

So I do not know what is considered a failure to change the value as per the documentation (`On failure to change the value, false is returned.`).
To Top