Page MenuHomePhabricator

Deprecate PHPSessionHandler and $wgPHPSessionHandling
Closed, ResolvedPublic

Description

In T362324, @Tgr wrote:

PHPSessionHandler registers SessionManager as a PHP session handler, which means that SessionManager methods are invoked (through PHPSessionHandler methods) at various points in the request lifetime. This is in theory only necessary for compatibility with extension code which uses PHP session handling ($_SESSION, session_start() etc), which hopefully doesn't happen anymore as it was deprecated a decade ago.

In T362324: Disable PHPSessionHandler in Wikimedia production PHPSessionHandler has been disabled on Wikimedia wikis by setting $wgPHPSessionHandling = 'disable'. We should eventually do the same in the default MediaWiki configuration. Removing these features would greatly simplify the code.

Next step: set $wgPHPSessionHandling = 'warn', maybe add some @deprecated tags.

Event Timeline

matmarex moved this task from Blocker to Deprecate or remove on the MW-1.45-release board.
matmarex added a subscriber: Tgr.
matmarex added a subscriber: Hemmanttt.

Hi @Hemmanttt, I assume you're not currently working on this. We need to complete this work before the MediaWiki 1.45 release (due next month), so I will take over this task.

Change #1190344 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] Deprecate PHPSessionHandler and $wgPHPSessionHandling

https://gerrit.wikimedia.org/r/1190344

Change #1190344 merged by jenkins-bot:

[mediawiki/core@master] Deprecate PHPSessionHandler and $wgPHPSessionHandling

https://gerrit.wikimedia.org/r/1190344

59467cab835a (1190344: Deprecate PHPSessionHandler and $wgPHPSessionHandling) seems to have introduced a new deprecation warning(/test failure) when I run tests locally on mediawiki/core:

$ composer phpunit:entrypoint -- tests/phpunit/includes/session/SessionBackendTest.php
Using PHP 8.1.34
Running with MediaWiki settings because there might be integration tests
PHPUnit 9.6.21 by Sebastian Bergmann and contributors.

.................E...                                             21 / 21 (100%)

Time: 00:00.320, Memory: 55.43 MB

There was 1 error:

1) MediaWiki\Tests\Session\SessionBackendTest::testResetIdOfGlobalSession
Use of $_SESSION was deprecated in MediaWiki 1.27. [Called from session_write_close in (internal function)]

/[...]/mediawiki/core/includes/debug/MWDebug.php:386
/[...]/mediawiki/core/includes/debug/MWDebug.php:357
/[...]/mediawiki/core/includes/debug/MWDebug.php:238
/[...]/mediawiki/core/includes/GlobalFunctions.php:787
/[...]/mediawiki/core/includes/session/PHPSessionHandler.php:354
/[...]/mediawiki/core/includes/session/SessionBackend.php:309
/[...]/mediawiki/core/tests/phpunit/includes/session/SessionBackendTest.php:1037
=== Logs generated by test case
[...]
===

Courtesy link: SessionBackendTest::testResetIdOfGlobalSession

Happy to file this as a separate task if folks would prefer :)

Hm! It seems like this is happening because we've not disabled it by default, and I think it will also affect CI, hence dev local environments. It was disabled in production in T362324: Disable PHPSessionHandler in Wikimedia production (and sub-tasks), but we may need to do this for CI & local env; otherwise, but we're still to do it by default, so it'll inherit the default config from MainConfigSchema and use that, which is set to 'warn' at the moment.

@matmarex, would it suffice if we just hide the deprecation warnings in this case? Or is it time to set the default config for this to 'disable'?

Happy to file this as a separate task if folks would prefer :)

Maybe you could file this as a separate task? I think this is affecting CI too. What happens if you set $wgPHPSessionHandling = 'disable' in your LocalSettings.php? Does the issue go away?

Change #1226250 had a related patch set uploaded (by D3r1ck01; author: Derick Alangi):

[mediawiki/core@master] tests: Hide deprecation warning for PHPSessionHandler

https://gerrit.wikimedia.org/r/1226250

@A_smart_kitten, since the default configuration is set to 'warn', this is expected, I think, but I also understand that it might cause confusion during local development.

The goal is to disable this in the future entirely and remove the entire PHPSessionHandling code.

What happens if you set $wgPHPSessionHandler = 'disable' in your LocalSettings.php? Does the issue go away?

Yep, the failure goes away with $wgPHPSessionHandling = 'disable'; :) [0]
(I'm not yet completely clear yet on why this doesn't seem to show up in WMF CI - presumably if it did, the patch in question wouldn't have been able to be merged last September. I guess that maybe $wgPHPSessionHandling might be set to either 'enable' or 'disable' somewhere in CI's LocalSettings.php, but a Codesearch didn't find where that might be happening...)

[0] edit: I guess this makes this failure a form of T277470: Ignore (most) of LocalSettings.php when running PHPUnit (fix surprise test failures)

Change #1226250 merged by jenkins-bot:

[mediawiki/core@master] tests: Hide deprecation warning for PHPSessionHandler

https://gerrit.wikimedia.org/r/1226250

Change #1226319 had a related patch set uploaded (by A smart kitten; author: Derick Alangi):

[mediawiki/core@REL1_45] tests: Hide deprecation warning for PHPSessionHandler

https://gerrit.wikimedia.org/r/1226319

Change #1226319 merged by jenkins-bot:

[mediawiki/core@REL1_45] tests: Hide deprecation warning for PHPSessionHandler

https://gerrit.wikimedia.org/r/1226319