Skip to content
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

Worker mode #1

Open
dunglas opened this issue Nov 8, 2022 · 15 comments
Open

Worker mode #1

dunglas opened this issue Nov 8, 2022 · 15 comments

Comments

@dunglas
Copy link
Owner

dunglas commented Nov 8, 2022

Currently, the worker mode of FrankenPHP isn't used.

The best way of supporting the worker mode would probably be to patch Drupal to use Symfony Runtime: https://www.drupal.org/project/drupal/issues/3313404

In the meantime, using this package or creating an ad-hoc implementation could do the trick.

@back-2-95
Copy link
Contributor

back-2-95 commented Nov 9, 2022

Drupal 10 has Symfony 6. Dunno yet if it helps with the implementation.

Update: I tried el7cosmos/drupal-runtime and it works... I guess. There are some weird things like when I click links in the menu, I might get wrong page or I get right page on 2nd or 3rd click.

If I comment out FRANKENPHP_CONFIG from docker-compose.yml and recreate containers, site works nicely.

So something still missing with Worker mode.

Update 2: cannot get it working anymore 🤷

@back-2-95
Copy link
Contributor

Not sure how to use https://github.com/el7cosmos/drupal-runtime. I setup it as instructed in the repo. Do I need to somehow change index.php so using the index.php from el7cosmos is not enough? Also don't know what to do with that template file. It seems that it just scaffolds index.php and update.php from assets folder.

In docker-compose.yml I had FRANKENPHP_CONFIG="worker ./public/index.php"

@dunglas
Copy link
Owner Author

dunglas commented Nov 16, 2022

This looks related to what is done in Drupal\Core\Session\SessionHandler because if I comment https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php#L397, the error disappears.

@dunglas
Copy link
Owner Author

dunglas commented Nov 16, 2022

It looks like Drupal sessions aren't compatible with workers. They don't work with RoadRunner either: https://www.drupal.org/project/drupal/issues/2218651

@back-2-95
Copy link
Contributor

I linked this issue to that issue on Drupal.org

@andypost
Copy link

Is there any benefits using it not in worker mode comparing to php-fpm?

Or it makes sense only after Drupal can clean-up session handling and adopt SF runtime?

@andypost
Copy link

The last attept to make it work was https://gitlab.com/daffie/swoole

@slim
Copy link

slim commented Oct 5, 2023

I'm trying to make it work with el7cosmos/drupal-runtime I followed the instructions and added the composer commands to the Dockerfile. Container builds smoothly, composer does not seem to complain. But I get a dry error when I request installer.php :

 Fatal error: Cannot redeclare format_size() (previously declared in /opt/drupal/web/core/includes/common.inc:136) in /opt/drupal/vendor/drupal/core/includes/common.inc on line 175

what would be the appropriate way to debug this kind of errors ? add xdebug extension to frankenphp ? install symfony-profiler ? shell to the container ?(container has no shell) mount the drupal project root locally on my machine ?

@back-2-95
Copy link
Contributor

@slim did you try like in this PR: #9 ?

@slim
Copy link

slim commented Oct 6, 2023

@back-2-95 I did not use your composer.json, I just added composer commands to the Docker file

--- a/Dockerfile
+++ b/Dockerfile
@@ -20,6 +20,11 @@ WORKDIR /opt/drupal
 RUN set -eux; \
        export COMPOSER_HOME="$(mktemp -d)"; \
        composer create-project --no-interaction --no-progress "drupal/recommended-project:$DRUPAL_VERSION" ./; \
+    # Worker mode using Symfony Runtime
+    composer config allow-plugins.symfony/runtime 1; \
+    composer config --json --merge extra.drupal-scaffold.allowed-packages '["el7cosmos/drupal-runtime"]'; \
+    composer config extra.runtime.autoload_template vendor/el7cosmos/drupal-runtime/assets/autoload_runtime.template; \
+    composer require el7cosmos/drupal-runtime:1.0.x-dev; \
        chown -R www-data:www-data web/sites web/modules web/themes; \
        rm -rf /app/public; \
        ln -sf /opt/drupal/web /app/public; \

@slim
Copy link

slim commented Oct 6, 2023

@back-2-95 I just used a custom composer.json like you did (I copied it from a non docker install of Drupal + el7cosmos/drupal-runtime) and everything seems to work all right! thank you 🙏

@back-2-95
Copy link
Contributor

Looking forward seeing what you can get done with it. Please check different challenges which were faced earlier like Drupal sessions.

@slim
Copy link

slim commented Oct 6, 2023

FYI session issue seems to be still there.

@slim
Copy link

slim commented Oct 10, 2023

So how to make sure I'm running in worker mode ? I installed the runtime/frankenphp-symfony component and made sure the environment variable APP_RUNTIME is set to Runtime\FrankenPhpSymfony\Runtime in my container. If I change APP_RUNTIME to something wrong I get a fatal error. Is there a better way to be 💯 sure it's runnning in worker mode ?

@dunglas
Copy link
Owner Author

dunglas commented Oct 11, 2023

To be 100% sure, you can check if the FRANKENPHP_WORKER environment variable is set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants