Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Sessions expire too soon

Tags:

php

session

I'm running a website with a nginx server with PHP Fastcgi on a VPS. I tried to configure the php.ini (in /etc/php5/cgi) to have PHP session last longer than 3 days (259200 seconds), but it didn't work and my php sessions don't last more than one hour.

My current session config in the php.ini:

session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 259200
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 259200
session.bug_compat_42 = Off
session.bug_compat_warn = Off
session.referer_check =
session.entropy_length = 0
session.cache_limiter = nocache
session.cache_expire = 259200
session.use_trans_sid = 0
session.hash_function = 0

What may be the problem here?

like image 524
NeDark Avatar asked Dec 04 '11 00:12

NeDark


People also ask

How do you increase the session expire time in PHP?

If you use PHP's default session handling, the only way to reliably change the session duration in all platforms is to change php. ini. That's because in some platforms, garbage collection is implemented through a script that runs every certain time (a cron script) that reads directly from php.

How long do PHP sessions last?

By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application.


1 Answers

This sounds a bit like Ubuntu or Debian on the server. If I rememeber correctly there is a cronjob somewhere (installed either by the php5 or the php5-common package) which cleans out your session directory more often.

I'd recommend you configure your sessions to be saved somewhere else (than the default). Adjust session.save_path and verify to cronjob doesn't empty it.

The cronjob is somewhere like /etc/cron.d/php - to be certain, run dpkg -L php5 or dpkg -L php5-common. Assuming you are on Ubuntu (or Debian) this should show you the location of all installed files.

like image 163
Till Avatar answered Oct 01 '22 16:10

Till