1

When I edit a page and keep it open for a long time I get the error "Sorry! We could not process your edit due to a loss of session data. Please try again. If it still does not work, try logging out and logging back in" when trying to save the page.

I assume it has something to do with sessions? If so how can I increase the maximum session time? I've tried session.gc_maxlifetime in php.ini (yes, I restarted Apache) but that makes no difference (which means I tried 30 seconds but I still could save the page after editing for some minutes). Or do I've to use a MW configuration settings?

waanders
  • 8,907
  • 22
  • 70
  • 102
  • Have you tried [this thorough answer](http://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php) on session timeouts on PHP/Apache including `session_set_cookie_params`? [MediaWiki.org](https://www.mediawiki.org/wiki/Manual_talk:Configuration_settings) indicate this is a PHP issue, so `session.gc_maxlifetime` should be your answer. – Egg Feb 03 '16 at 13:35
  • Well, I'm a system admin not a programmer (on this project). I don't want to change program or script code, just config settings. Should this be possible? As I said, I tried the session.gc_maxlifetime setting – waanders Feb 03 '16 at 13:45
  • The default is 1440 (seconds) - 24 minutes. The php.ini file should already contain this value which you can just update? You could try adding these paramters to your LocalSettings.php file in MediaWiki: `ini_set(session.cookie_lifetime, 3600); ini_set(session.gc_maxlifetime, 3600);` (3600 seconds = 1 hour)? – Egg Feb 03 '16 at 14:09
  • 1
    see manual: https://www.mediawiki.org/wiki/Manual:$wgCookieExpiration – Gunnar Bernstein Feb 28 '21 at 06:16

3 Answers3

1

If $wgSessionsInObjectCache is enabled, increase $wgObjectCacheSessionExpiry. Otherwise, sessions are saved by PHP and you should change the relevant configuration, as suggested by other comments.

Tgr
  • 27,442
  • 12
  • 81
  • 118
0

I just went through that issue and here is what solved it for me.

  1. Upgrade MediaWiki to the latest version (Important) i had an issue with version 1.26.0.

  2. MediaWiki handles its session through its code. Leave php and apache alone for now. Focus on the configuration settings for media wiki.

  3. Try to set $wgCookieExpiration = 86400 (1 day for example) and set $wgExtendedLoginCookieExpiration = null in your configuration and see what happens.

Hopefully that solves your issues.

winteck
  • 417
  • 2
  • 4
  • 18
0

In my case had changed the $wgMainCacheType to 'CACHE_ACCEL' to enable apcu and opcache in php server itself. I had left $wgSessionCacheType out of the config file at default of 'CACHE_ANYTHING'. In this configuration, the token is stored on the php "server" APCu cache.

## Shared memory settings
$wgMainCacheType = CACHE_ACCEL;

This caused the sort of 'live' in-flight session token to get cleared fairly quickly as APCu cleared its state, which is more for performance and intended to be fairly dynamic.

Thus I'd get the "Sorry! We could not process your edit due to a loss of session data." really quickly and inconsistently, like 30 seconds, 1-2 minutes or maybe 5 mins. This made it really annoying.

Page edits in MediaWiki require the the matching sort of 'live token' to complete. Normally it just gets regenerated constantly if missing, except on submitting edits. I think this was to prevent accidental stale edits from someone who had already logged out, as a security measure.

What was happening was that the browser was fine, but the live token cache object in APCu was getting cleared as hadn't been used soon enough, because I had stopped to edit..., and the server side had no matching token on submit.

What I needed to add was:

$wgSessionCacheType = CACHE_DB;

This causes the session security token to get persisted correctly according to the MediaWiki rules, and not the dynamic object caching rules. Which is explained here: https://www.mediawiki.org/wiki/Manual:$wgSessionCacheType

For proper operation this must be set to a persistent cache, and if there are multiple servers that might serve a single client's requests the cache must be shared by all of them.

If $wgMainCacheType is set to CACHE_ACCEL and this is left at its default CACHE_ANYTHING, the cache used may not meet these requirements.

The solution is to set this to an appropriate cache, such as CACHE_DB.

And here: https://www.mediawiki.org/wiki/Manual:$wgMainCacheType

Since MediaWiki 1.27, PHP sessions are stored in a cache, depending on the variable of this setting, unless overridden by $wgSessionCacheType. This may cause problems when CACHE_ACCEL is used if apcu is misconfigured (see task T147161).

CACHE_ACCEL only supports APCu or WinCache since MediaWiki 1.31.

Beeeaaar
  • 1,010
  • 9
  • 19