-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't call session_start() before CMS bootstrap (PHP 7.2 compat) #14074
Conversation
(Standard links)
|
On general policy grounds, 👍 -- it definitely sounds better to let the normal bootstrap process handle the session start. In theory, the test-coverage in Aside: Actually... creating any kind of session during execution of |
Side note: CiviCRM has some other front controllers that call session_start(), like soap.php - but these should be ok if they don't also bootstrap the CMS. These do result in some "weird" behavior though: Whatever session configuration is defined in the PHP config files will be started up, where otherwise you would expect this configuration to be overridden by Drupal. E.g. session files will show up in the /tmp directory rather than using Drupal's session store. |
Meta sidenote: As long as we use If possible, consider using a CMS-bootstrapped endpoint; for (I may be out of date on this front ...) |
My understanding was that civicrm/ajax/rest is designed for requests from browser JS. Whereas we're using extern/rest.php to have other apps talk to CiviCRM. Presumably we could have these other apps simulate a browser if we had to, but it's a bit clunky. |
I did a deep dive on why we were getting a 500 error (in addition to logging warnings to the error log), because I could not reproduce the 500 error on a barebones Civi+Drupal install. Turns out that there is an incompatibility with some of the Drupal modules on our site, which I am able to resolve to some extent. So now we just have numerous warnings and notices being logged by this bug, but not the fatal 500 error page. E.g. as a result on this bug, the global $user object does not exist, which Drupal modules are not happy with. I removed some other superflous comments here because the warnings being thrown in early bootstrap led to weird problems re: loading classes in our error handling code, but I don't think that was another issue in Civi itself. |
Jenkins re test this please |
It's likely that the 3 lines above could also be removed, if we're not actually starting a session here?
|
Seamus's additional E2E test has been merged. Combining this with #14186 shows an almost green E2E matrix. Let's do it! |
Overview
CiviCRM's extern/rest.php calls session_start() before bootstrapping the CMS. However, configuring the session is one of the bootstrap steps for Drupal (and perhaps other CMS), and on PHP ≥ 7.2, you cannot configure the session after starting it. In addition, generally speaking, Drupal does not want anything besides itself to start the session. This is presumably why there is some logic in CRM_Core_Session::initialize() for starting the session differently on Drupal.
Before
When sending a request to extern/rest.php on PHP ≥ 7.2, the following error is logged: Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in drupal_environment_initialize() (line 695 of includes/bootstrap.inc). In addition, other errors/notices in Drupal modules may be logged.
After
We no longer call session_start() in extern/rest.php. I believe this should work because commit f320e5c should result in a session being initialized during CRM_Utils_REST::loadCMSBootstrap(). If not.. then more work is needed here :)