I'm trying to set up the server to increase the lifetime session to 2 hours to be able to save surveys (Limesurvey) after some time of inactivity. If I try to save after 45 minutes it shows up an error message saying that the session has expired.
I have been reading a lot to find solutions but what I have found so far, didn't work. Probably because I'm missing something.
This is what I have:
Plesk 12.5.30
Limesurvey 2.06+ Build 150831
PHP 5.3.10
The settings in config-defaults.php (Limesurvey) have:
$config['iSessionExpirationTime'] = 7200;
2 hours which is ok, is what I want but does not work. So I thought that my server settings were overriding the Limesurvey settings. So I went to plesk > domains, selected my domain and clicked on PHP settings, scrolled down and added to the "additional instructions" these two lines:
session.cookie_lifetime = 7200
session.gc_maxlifetime = 7200
So now all my additional instructions looks like this:
max_input_vars = 5000
suhosin.memory_limit = 128
suhosin.post.max_value_length = 5000000
suhosin.post.max_vars = 5000
suhosin.request.max_value_length = 5000000
suhosin.request.max_vars = 5000
suhosin.simulation = 1
session.cookie_lifetime = 7200
session.gc_maxlifetime = 7200
But it didn't work anyways, I'm still having the same error when trying to save a survey when 45 minutes have elapsed.
Any help would be great.
Thanks a lot.
Check cron tasks:
cat /etc/cron.d/php5
# /etc/cron.d/php5: crontab fragment for php5
# This purges session files in session.save_path older than X,
# where X is defined in seconds as the largest value of
# session.gc_maxlifetime from all your SAPI php.ini files
# or 24 minutes if not defined. The script triggers only
# when session.save_handler=files.
#
# WARNING: The scripts tries hard to honour all relevant
# session PHP options, but if you do something unusual
# you have to disable this script and take care of your
# sessions yourself.
# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean
Usually the session directory is shared by all applications on the same webspace.
So if you have other applications (CMS) running they might set the session timeout shorter and so the LimeSurvey sessions get kicked, too.
Related
I have a wordress blog and there is plugin that does around 20000 SQL inserts on user request. I noticed that the process takes long time, which is normal, but the request times out at 30 seconds.
I checked PHP settings and notice that PHP max_execution_time was 30 second, so I increased it to 90, but the requst keeps to timeout at 30 seconds (I even logged what does ini_get('max_execution_time') return and it says "30". Then, I checked if there are any apache directives that limit request time and found that there is a "TimeOut" directive ( http://httpd.apache.org/docs/2.2/mod/core.html#timeout )
Its value was 60 and I increased it to 90 as well, but the problem persist - the request times out after 30 seconds as it was before I changed anything.
as a note: I restart the server after I do any modification
By modifying your PHP Settings
That’s not easy, as you need to have access to your server, or a way to change your PHP settings. If you have access to your php.ini, you need to look for the max_execution_time variable and set it to the number of seconds you would like, 60 seconds for example.
max_execution_time = 60
If that doesn’t work, or can’t access your php.ini, you can also try to set this variable by using the .htaccess (at the root of your WordPress install). You can add this line.
php_value max_execution_time 60
If you set the value to 0 (instead of 60, here), the process will be allowed to run forever. Don’t do this, you will run into much bigger issues, extremely difficult to resolve.
By calling a function in PHP
This is generally not really recommended to do this. But if you know what you are doing, you can tell PHP that you would like the process to run for more time. For this, you could write this call in your theme, in the functions.php for example.
set_time_limit(100);
I need to run a really slow PHP/MySQL script once, on my local server.
The problem is that Laravel times out after 60 seconds with the message "Maximum execution time of 60 seconds exceeded".
I have set
max_execution_time = 360
and
max_input_time = 360
in my php.ini. The settings are there (checked phpinfo()) but Laravel still times out after 60 seconds. Is there anything in Laravel that I can set as well?
I dont think Laravel will override PHP settings. After changing the settings in your ini file, you have to restart the server to take effects.
So check whether you have restarted your server after the change in the settings
I have added the following lines in my htaccess file :
php_value session.cookie_lifetime 14400
php_value session.gc_maxlifetime 14400
Also have added a php.ini file in the root directory with the following code :
session.gc_maxlifetime = 14400
session.cookie_lifetime = 14400
Also inside the php code have added the following lines :
ini_set('session.cookie_lifetime',14400);
ini_set('session.gc_maxlifetime',14400);
setcookie("_lid", $lid, time() + 14400);
So basically the session should work for 4 hours. But it is getting timed out in about 24 mins or so which is the default timeout time in php.
I may be missing something. Would be great if someone can provide some inputs.
Thanks
I was having the exact same problem - the session.gc_maxlifetime & session.cookie_lifetime values were set but appeared to not be honoured... Then, I found a comment on an old thread which clearly needs a lot more recognition:
How do I expire a PHP session after 30 minutes?
Please note that at least two settings are crucial to setting the
session time, and maybe three. The two certainly crucial ones are
session.gc_maxlifetime and session.cookie_lifetime (where 0 is not the
same as some long number). For complete, 100% certainty of allowing
long times, it may also be necessary to set the session.save_path, due
to varying OS-controled cleanup time on the /tmp directory where
session files get stored by default. – #Kzqai Apr 7 '11 at 8:04
I can't figure out why my PHP sessions are timing out after 24 minutes even after I set session.gc_maxlifetime to a very high amount.
I specifically went into my /tmp folder to look at the session data files being created. Just as you would expect with PHP's garbage collecting, every so often the older files would be deleted. Every time, it seemed to be the files that were > 24 minutes old. This seems strange because the default of session.gc_maxlifetime is 1440 seconds (24 minutes). But I changed that variable, and nothing else in php.ini is set to 1440. What could possibly be causing this?
I can't understand...
If you don't want to have files older than 24 minute, then you don't need to change anything.
Otherwise, just extend the 1440 value to the one you need and restart Apache.
Which value did you assign to the session.gc_maxlifetime?
I already altered my php.ini in Apache to have these settings:
session.gc_maxlifetime = 1440
session.cache_expire = 1500
But my sessions are not that long. The problem is that I am not certain which settings would "do the trick"
Ideally I am looking for the right configuration to have the session last 12 hours. Could anyone help me with that?
do you also have set session.cookie_lifetime = 0 ?
and maybe somewhere in your scripts or some included scripts the session lifetime is set to another value?
The default "0" value means that the cookie stays alive until the browser is closed. This is also the default value, if not set in php.ini.
Source: http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime
session.gc_maxlifetime is measured in seconds, so your setting of 1440 will expire after 24 minutes. (see: http://php.net/session.gc-maxlifetime)
For 12 hour session I believe you need:
session.gc_maxlifetime = 43200
session.cache_expire = 720
session.cookie_lifetime = 0
Have a look at:
session.cookie_lifetime x
Where x is the lifetime in seconds
Also, if you are on a shared host, make sure the session data under /tmp is not removed by the host with some sort of clean script. Some hosts clear /tmp every 10 minutes.