logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$15
What would cause PHP sessions to time out very fast?

This is actually a question about WPQuestions.com, not WordPress. Several people have complained that the sessions on this site time out quickly, and they are forced to log in every 5 minutes. I've noticed this too. The PHP sessions on this server are stored in this folder:

/var/lib/php5

I have actually started watching that folder, checking every few minutes to get a sense of how fast the sessions disappear. There are some weird cases. Sometimes I am cruising around WP Questions and suddenly my session id changes, as a click from one page to another. PHP sessions should not function this way. But the files do disappear, suddenly, from /var/lib/php5, and they disappear before they should.

Has anyone seen problems like this before? Any suggestions?

Lawrence Krubner | 01/20/13 at 5:43pm Edit
Tutorial: How to assign prize money


(7) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/20/13
    6:05pm
    Martin Pham says:

    Hi Lawrence,
    You can check value of php sessions timeout in php.ini


    ;http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime
    session.gc_maxlifetime = second_value

    if you use session cookie

    ; Lifetime in seconds of cookie or, if 0, until browser is restarted.
    ; http://php.net/session.cookie-lifetime
    session.cookie_lifetime = 0


    please modify these values ​​to suit your requirements and restart apache/nginx/...

  • avatar
    Last edited:
    01/21/13
    4:08pm
    Mike Van Winkle says:

    If your site is using cloudflare or the server is using Varnish, this will often cause inconsistent session IDs, depending on the configuration.

  • avatar
    Last edited:
    01/22/13
    2:35pm
    Daniel Yoen says:

    try this : http://stackoverflow.com/a/6069585

    Hope this help

    Previous versions of this answer: 01/22/13 at 2:35pm

  • avatar
    Last edited:
    01/22/13
    5:14pm
    Lawrence Krubner says:

    I am sorry about my previous reply, that was actually meant for a different question that I had asked. I accidentally posted it here.

  • avatar
    Last edited:
    01/22/13
    5:15pm
    Lawrence Krubner says:

    This is from my php.ini:

    php -i | grep session
    session
    session.auto_start => Off => Off
    session.bug_compat_42 => Off => Off
    session.bug_compat_warn => Off => Off
    session.cache_expire => 180 => 180
    session.cache_limiter => nocache => nocache
    session.cookie_domain => no value => no value
    session.cookie_httponly => Off => Off
    session.cookie_lifetime => 0 => 0
    session.cookie_path => / => /
    session.cookie_secure => Off => Off
    session.entropy_file => no value => no value
    session.entropy_length => 0 => 0
    session.gc_divisor => 1000 => 1000
    session.gc_maxlifetime => 1440 => 1440
    session.gc_probability => 0 => 0
    session.hash_bits_per_character => 5 => 5
    session.hash_function => 0 => 0
    session.name => PHPSESSID => PHPSESSID
    session.referer_check => no value => no value
    session.save_handler => files => files
    session.save_path => /var/lib/php5 => /var/lib/php5
    session.serialize_handler => php => php
    session.use_cookies => On => On
    session.use_only_cookies => On => On
    session.use_trans_sid => 0 => 0
    root@dublin:/home/lawrence#

  • avatar
    Last edited:
    01/22/13
    5:16pm
    Lawrence Krubner says:

    Interesting. The site is, in part, using the Symfony framework, which does some black magic regarding the cache. I will turn off the cache and see if that helps.

  • avatar
    Last edited:
    01/22/13
    5:22pm
    Lawrence Krubner says:

    Wow, this is really interesting:

    On a shared server that runs multiple sites that use a shared session directory the session.gc_maxlifetime is in effect the shortest lifetime of all sites accessing that shared directory.


    We have been working on cloud computers. I wonder if the other instances on the same machine effect the session timeout? Very interesting if true, though that suggests that all the sessions are being written to the same place, which can not be true because I can sudo to root and look in /var/lib/php5 and see that the sessions correspond to my websites.

This question has expired.





Current status of this question: Community pot



Please log in to add additional discourse to this page.





Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.