joanhey / AdapterMan

Run almost any PHP app faster and asynchronously with Workerman, without touch 1 line of code in your fw or app. Also use it as Serverless.
https://twitter.com/adaptermanphp
MIT License
755 stars 50 forks source link

drupal support? #40

Open terryzwt opened 1 year ago

terryzwt commented 1 year ago

How to use it on Drupal?

joanhey commented 1 year ago

https://github.com/joanhey/AdapterMan/blob/master/recipes/drupal.md

joanhey commented 1 year ago

I'll try to create a dockerfile with Adapterman and Drupal, when I have free time.

PD: recommendations for any Drupal demo site are welcome, now I use Umami demo, but looks like it's deprecated in Drupal site.

terryzwt commented 1 year ago

I run php server.php start, nothing happened.

joanhey commented 1 year ago

I test it locally with Umami demo and Nginx proxy (for the static files)

https://github.com/joanhey/AdapterMan/assets/249085/c12f5675-fa22-4dc8-8f92-79d0951e10bb

PD: Drupal 9.5.10

terryzwt commented 1 year ago

Great video. may you show screenshot of php server.php start? Here is mine, the process just quit immediatly.

image
joanhey commented 1 year ago

image

This image is from the video example, that I made just now.

It's very strange that your call make nothing, not even show an error. Do you have PHP-cli installed ?

joanhey commented 1 year ago

server.php

<?php
global $autoloader;
$autoloader = require_once __DIR__ . '/vendor/autoload.php';

use Adapterman\Adapterman;
use Workerman\Worker;

Adapterman::init();

$http_worker                = new Worker('http://0.0.0.0:8080');
$http_worker->count         = (int) shell_exec('nproc') * 4;
$http_worker->name          = 'AdapterMan';

$http_worker->onWorkerStart = function () {
    //init();
    require __DIR__.'/start.php';
};

$http_worker->onMessage = static function ($connection) {

    $connection->send(run());
};

Worker::runAll();

start.php

<?php

/**
 * @file
 * The PHP page that serves all page requests on a Drupal installation.
 *
 * All Drupal code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
 */

use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

//$autoloader = require_once __DIR__ . '/vendor/autoload.php';
global $autoloader;
global $kernel; 

$kernel = new DrupalKernel('prod', $autoloader);

function run(): string
{
    global $kernel;

    ob_start();

    $request = Request::createFromGlobals();
    $response = $kernel->handle($request);
    $response->send();
    $kernel->terminate($request, $response);

    return ob_get_clean();
}
joanhey commented 1 year ago

nginx conf

server {
    listen 80;
    listen [::]:80;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /media/joan/DataSSD/git/drupal;

    # Add index.php to the list if you are using PHP
    #index index.php;

    server_name drupal;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri @php;
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.php$ {
    location @php {
    #   include snippets/fastcgi-php.conf;
        proxy_pass http://localhost:8080;
                proxy_set_header Host $host;
                proxy_http_version 1.1;
                proxy_set_header Connection "";
    }

    location = /index.php {
        return 301 /;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}
terryzwt commented 1 year ago

thanks, I can run now with errors:

image
joanhey commented 1 year ago

Yes, I know. I fixed 1 hour ago. https://github.com/joanhey/AdapterMan/commit/1506550ca9b209fe32d8440ab426b06436ff443f But still without the fix it's working.

Try to use dev-master in composer.

joanhey commented 1 year ago

I don't have time to tests all the frameworks and applications. Test Drupal, and if you find a problem, create an issue. Thanks.

terryzwt commented 1 year ago

Drupal version

# drush st
Drupal version   : 10.1.2
Site URI         : http://default
DB driver        : pgsql
DB hostname      : postgresql
DB port          : 5432
DB username      : postgres
DB name          : org_hr
Database         : Connected
Drupal bootstrap : Successful
Default theme    : bartik
Admin theme      : claro
PHP binary       : /usr/bin/php82
PHP config       : /etc/php82/php.ini
PHP OS           : Linux
PHP version      : 8.2.1
Drush script     : /usr/local/bin/drush
Drush version    : 11.6.0
Drush temp       : /tmp
Drush configs    : /var/www/html/vendor/drush/drush/drush.yml
Install profile  : standard
Drupal root      : /var/www/html/web
Site path        : sites/default
Files, Public    : sites/default/files
Files, Private   : sites/default/files/private
Files, Temp      : /tmp

with the errors:

The website encountered an unexpected error. Please try again later.

Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The class "Drupal\Core\Field\Annotation\FieldFormatter" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Drupal\Core\Field\Annotation\FieldFormatter". If it is indeed no annotation, then you need to add @IgnoreAnnotation("FieldFormatter") to the _class_ doc comment of class Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter. in Doctrine\Common\Annotations\AnnotationException::semanticalError() (line 40 of /var/www/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php).
Drupal\Component\Annotation\Doctrine\DocParser->Annotation() (Line: 640)
Drupal\Component\Annotation\Doctrine\DocParser->Annotations() (Line: 338)
Drupal\Component\Annotation\Doctrine\DocParser->parse('/**
 * Provides a default comment formatter.
 *
 * @FieldFormatter(
 *   id = "comment_default",
 *   module = "comment",
 *   label = @Translation("Comment list"),
 *   field_types = {
 *     "comment"
 *   }
 * )
 */', 'class Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter') (Line: 101)
Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader->getClassAnnotations(Object) (Line: 125)
Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader->getClassAnnotation(Object, 'Drupal\Core\Field\Annotation\FieldFormatter') (Line: 145)
Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery->getDefinitions() (Line: 86)
Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions() (Line: 291)
Drupal\Core\Plugin\DefaultPluginManager->findDefinitions() (Line: 181)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 22)
Drupal\Core\Plugin\DefaultPluginManager->getDefinition('author', ) (Line: 202)
Drupal\Core\Field\FormatterPluginManager->getDefaultSettings('author') (Line: 153)
Drupal\Core\Field\FormatterPluginManager->prepareConfiguration('entity_reference', Array) (Line: 357)
Drupal\Core\Entity\EntityDisplayBase->setComponent('uid', Array) (Line: 412)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->setComponent('uid', Array) (Line: 202)
Drupal\Core\Entity\EntityDisplayBase->init() (Line: 153)
Drupal\Core\Entity\EntityDisplayBase->__construct(Array, 'entity_view_display') (Line: 178)
Drupal\Core\Entity\Entity\EntityViewDisplay->__construct(Array, 'entity_view_display') (Line: 48)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->__construct(Array, 'entity_view_display') (Line: 418)
Drupal\Core\Entity\EntityStorageBase->mapFromStorageRecords(Array) (Line: 41)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage->mapFromStorageRecords(Array) (Line: 186)
Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple(Array) (Line: 312)
Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 118)
Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplays(Array, 'teaser') (Line: 280)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 238)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 377)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 474)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 60)
__TwigTemplate_25a42e7d609174d3cb81614d38e85df0->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array, Array) (Line: 40)
Twig\TemplateWrapper->render(Array) (Line: 53)
twig_render_template('core/modules/views/templates/views-view-unformatted.html.twig', Array) (Line: 372)
Drupal\Core\Theme\ThemeManager->render('views_view_unformatted', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 474)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 110)
__TwigTemplate_313816e2bad9d7fd6c4f46fe717bd2b8->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array, Array) (Line: 40)
Twig\TemplateWrapper->render(Array) (Line: 53)
twig_render_template('themes/contrib/bartik/templates/classy/views/views-view.html.twig', Array) (Line: 372)
Drupal\Core\Theme\ThemeManager->render('views_view', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 171)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 27)
run() (Line: 22)
{closure}(Object, Array) (Line: 646)
Workerman\Connection\TcpConnection->baseRead(Resource) (Line: 311)
Workerman\Events\Select->loop() (Line: 1635)
Workerman\Worker::forkOneWorkerForLinux(Object) (Line: 1426)
Workerman\Worker::forkWorkersForLinux() (Line: 1400)
Workerman\Worker::forkWorkers() (Line: 560)
Workerman\Worker::runAll() (Line: 25)
joanhey commented 1 year ago

I need a Drupal 10 demo site to test it. Do you know any Drupal 10 demo ??

PD: but the error you sent, looks like a Semantical Error, nothing from Adapterman

terryzwt commented 1 year ago
  1. docker docker run -d --name drupal10 -p 8080:80 drupal:10
  2. composer: composer create-project drupal/recommended-project my_site_name_dir

https://www.drupal.org/docs/develop/using-composer/manage-dependencies