Hey folks!

I lately tried to get Drupal working with PHP-PM and thought about a little adjust that is absolutely required to get even basic functionality working. That functionality is basically that the HttpKernel/DrupalKernel allows a second request (more than one call against `DrupalKernel::handle`) without crashing.

Currently in the handle method calls always a method called `initializeSettings`, which is only necessary once. This patch basically makes sure, that method is only called once.

This gets the basic php-pm approach alive with Drupal. However, some common things currently don't work perfectly like session handling and css file name generation. I guess it's worth to merge this in, so other people don't stumble over the same when trying to get Drupal working with php-pm. :)

Cheers
Marc

Comments

marcjschmidt created an issue. See original summary.

larowlan’s picture

Category: Feature request » Task
Status: Active » Needs review

I think we should class this as a task, or failing that - a bug

Will work on a test in the morning

Thanks Marc, for php-pm and for contributing!

Status: Needs review » Needs work
dawehner’s picture

To be honest this issue should be more like a meta issue, given that there will be many potential subissues.

One problem which you will probably run into is #2613044: Requests are pushed onto the request stack twice, popped once which will polute your memory.

Crell’s picture

There can be a meta issue, sure, but this is one targeted fix. Just targeted fix it.

  1. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -624,7 +631,9 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
    -      $this->initializeSettings($request);
    +      if ($this->settingsInitialized){
    +          $this->initializeSettings($request);
    +      }
    

    Drupal coding standards say space before the {, and 2-space indent for the method body.

  2. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -954,6 +963,11 @@ public static function bootEnvironment() {
    +    if ($this->settingsInitialized) {
    +        throw new \LogicException('Can not initialize the kernel twice.');
    +    }
    

    2 space indent, please.

    Do we want to throw an exception here? It seems that the failure case results in the same post-condition as the success case: The kernel is now initialized and usable. Why not just return-early instead of throwing an exception, as the end result is still an acceptable state?

    Alternatively... maybe this is a good use case for an assertion?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

almaudoh’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.2 KB
new1.62 KB

I'm interested in this and I saw a small bug in the initial patch, so instead of a review, here's another patch.

-      $this->initializeSettings($request);
+      if ($this->settingsInitialized){
+          $this->initializeSettings($request);
+      }

This bit should actually check if the settings are NOT initialized, then initialize.

I also agree with #5, so removed the exception throwing as well and fixed the CS nits.

Status: Needs review » Needs work

The last submitted patch, 8: 2708827-8.patch, failed testing.

almaudoh’s picture

Status: Needs work » Needs review
soul88’s picture

Could you please explain, why do we need this check

+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -643,7 +650,9 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
+      if (!$this->settingsInitialized) {
+        $this->initializeSettings($request);
+      }

if we have this one?

protected function initializeSettings(Request $request) {
+    if ($this->settingsInitialized) {
+      return;
+    }

I mean, wouldn't it be enough to only check if settings were initialized in the initializeSettings method?

almaudoh’s picture

Could you please explain, why do we need this check

Good question, it's just to avoid the extra function call.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -643,7 +650,9 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
+      if (!$this->settingsInitialized) {
+        $this->initializeSettings($request);
+      }

If this is checked by initializeSettings already, why do we need to check it upfront as well?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

If this is supposed to help use Drupal with ReactPHP(and similar), shouldn't the initializeSettings() internally key the configuration by active site determined from the request?

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alauzon’s picture

StatusFileSize
new1.63 KB

The patch in #8 does not apply to 8.5.x-dev neither to 8.6.x-dev. Fortunately I could apply that patch manually on 8.6.x-dev and now I would like to publish the new patch. Since the patch cannot apply to 8.6.x-dev I cannot create an interdiff.

I'm new at publishing patches. Can you tell me if I can publish my new patch without an interdiff or else what do I do?

dawehner’s picture

@alauzon You did well! When you don't do any logic changes you also don't need to post an interdiff. But yeah patches and interdiffs are super weird 2018.

wim leers’s picture

@dawehner How about retro, retro cool or even retro chic? 😜

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Issue tags: +Needs issue summary update

Issue still makes sense, moreover reactPHP tagged LTS https://github.com/reactphp/react/releases/tag/v1.0.0

The numbers of running SF with reactPHP beats php-pm and sometimes php-fpm

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

Re-roll and address #14 (interdiff is bigger then patch) - we use this pattern already in \Drupal\Core\DrupalKernel::boot()

OTOH instead of new property we can check that Settings already initialized (probably try Settings::getInstance() catch ... or add helper method

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andypost’s picture

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

andypost’s picture

StatusFileSize
new1.28 KB

re-roll for 9.2

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
andypost’s picture

Issue tags: -Needs reroll
swatichouhan012’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB

Re-roll for 9.3

joachim’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

catch’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -244,6 +244,13 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
     
    +  /**
    +   * The state whether initializeSettings() has been called or not.
    +   *
    

    Can probably drop 'The state' here.

  2. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -1067,6 +1074,11 @@ public static function bootEnvironment($app_root = NULL) {
    +      // Early exit to prevent repeating resource expensive operations.
    

    Is this because it's expensive or because it will fatal? Should also say early return rather than early exit.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new856 bytes
new1.27 KB

It's expensive but may cause a fatal iirc

joachim’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we need to consider what should occur if Kernel::shutdown() is called. I think in this instance we should not reset it. Looking at the behaviour of ::boot() and how it interacts with $this->sitePath.

Therefore I think we need to document that this will still only occur once regardless of calling ::shutdown. Hmmm actually looking at things what happens if you have code calling \Drupal\Core\DrupalKernel::setSitePath() after a shutdown()? I think this change will break expectations.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

andypost’s picture

Issue tags: +DrupalCon Lille 2023
_utsavsharma’s picture

StatusFileSize
new1.27 KB
new1.27 KB

Patch for 11.x.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.