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

Can not get public assets? #9

Open
mouyong opened this issue Dec 14, 2022 · 31 comments
Open

Can not get public assets? #9

mouyong opened this issue Dec 14, 2022 · 31 comments
Labels
wontfix This will not be worked on

Comments

@mouyong
Copy link
Contributor

mouyong commented Dec 14, 2022

image

When I run it in laravel project and use dcat-admin + tenancy it say those error. but in php-fpm, it can run success.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

Cann't.

When I use (new Response)->withFile(); it throw error: Error: Class "Workerman\Protocols\Http\Response" not found in xxx

Because the workerman version is so old in composer.lock.

image

server.php:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Adapterman\Adapterman;
use Workerman\Worker;

Adapterman::init();

$http_worker                = new Worker('http://0.0.0.0:3000');
$http_worker->count         = 8;
$http_worker->name          = 'AdapterMan';

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

$http_worker->onMessage = static function ($connection, $request) {
    $file = __DIR__."/public/".ltrim($_SERVER['REQUEST_URI'] ?? '', '/');

    if (str_contains($file, '..')) {
        $response = new \Workerman\Protocols\Http\Response(403);

        return $connection->send($response);
    }

    if (is_file($file)) {
        $response = new \Workerman\Protocols\Http\Response();
        $response->withFile($file);

        return $connection->send($response);
    }

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

Worker::runAll();

Document: https://www.workerman.net/doc/workerman/http/response.html

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

composer config repositories.adapterman vcs https://github.com/mouyong/AdapterMan

composer require joanhey/adapterman:dev-master

server.php

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Adapterman\Adapterman;
use Workerman\Worker;

Adapterman::init();

$http_worker                = new Worker('http://0.0.0.0:3000');
$http_worker->count         = 8;
$http_worker->name          = 'AdapterMan';

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

$http_worker->onMessage = static function ($connection, $request) {
    $file = __DIR__."/public/".ltrim($_SERVER['REQUEST_URI'] ?? '', '/');

    if (str_contains($file, '..')) {
        $response = new \Workerman\Protocols\Http\Response(403);

        return $connection->send($response);
    }

    if (is_file($file)) {
        $response = new \Workerman\Protocols\Http\Response();
        $response->withFile($file);

        return $connection->send($response);
    }

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

Worker::runAll();

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

For now Adapterman only use Workerman 3.5.

Initally, Adapterman will be an App Server, and use a web server for the static files (Nginx, Nginx Unit, Apache, ...)

We can add to server static files too, but I think that is better handled by web servers : serve statics assets, TLS termination, Proxy, ...

But we are open to any ideas.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

In theory, if anybody want to use Adapterman with a popular framework, it's only for the performance.

The only way to scale more, it's use Adapterman , without any webserver, in separate servers. And you use a load balanced proxy server, to scale still more.
Or add different Workerman Apps (in the same server or not) to the same domain.
We need to abandon the monolithic apps.

Adapterman help to run any framework. But if you want to use all the features of Workerman, you can create more apps outside of your framework app.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

Example with Nginx:

location / {
         proxy_pass 127.0.0.1:8080;
         proxy_http_version 1.1;
         proxy_set_header Connection "";
}

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

image

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

it already proxy_pass to application, but cann't load laravel public path files.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

image

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

We only change the php-fpm for a proxy_pass, the rest of the config is the same than normal Laravel.

Example normal Laravel config:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html/blog/public;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name localhost;

    location / {
    try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
      try_files $uri /index.php =404;
      fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

With Adapterman:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html/blog/public;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name localhost;

    location / {
    try_files $uri $uri/ @backend;
    }

    location @backend {
         proxy_pass 127.0.0.1:8080; // or localhost:8080;
         proxy_http_version 1.1;
         proxy_set_header Connection "";
    }

    location ~ /\.ht {
        deny all;
    }
}

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

The config is the same than Nodejs or others app servers.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

it success load login page, but it cannot login by session.

image

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

image

the problem key is those in picture.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

We need to test more the session.
But I tested with Symfony and various Laravel apps without problems.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

can you give me your mail address? i can give you site address and account/password.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

maybe i should try create a new laravel project and install dcat/laravel-admin, then test adapterman in tomorrow.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

joanhey @ kumbiaphp.com

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

What type of session do you use: file, redis, memcached, ... ?

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

In Workerman 4 we can use more session types, but not in v3.5

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

redis

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

So I'll need to check the redis code in Laravel for now.
The session is the part, that I never used before for my API's and microservices.
So we need to fix more the session.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

And like before, we can create a Workerman session than don't need Redis.
Workerman is as fast as Redis.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

already send mail to you.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

Remember that the Eloquent ORM is very slow. Also when use it with Workerman.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

ok, have some suggest give me?

@mouyong
Copy link
Contributor Author

mouyong commented Dec 14, 2022

Sorry, Maybe i need to sleep.in tommorrow i will be see your Leaving a message.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

OK, see you tomorrow.

But Adapterman use Workerman v3.5, and in this version the session is fixed to filesystem.
But we can work to change it.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

Try temporally to use the default filesystem session.
To test that it's working with Adapterman.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

Some apps will not work with Workerman, but also not with Octane.
Because use global or static variables, that in a persistent app are never destroyed or cleaned.

@joanhey
Copy link
Owner

joanhey commented Dec 14, 2022

If you only use 1 server, you don't need Redis.
The use of Redis or Memcache, it is not for performance but for manage multiple app servers.

In Linux, using filesytem session, that session files will end up in Linux Filesystem Cache (RAM). Also normally the session use more read than write.
Or it's possible to force to use ram using TMPFS.
Example article:
https://eddmann.com/posts/storing-php-sessions-file-caches-in-memory-using-tmpfs/

@joanhey
Copy link
Owner

joanhey commented Dec 15, 2022

After test your app, the session is working with redis too.
But there is a strange behavior with the logout, that I'm checking to fix.

@mouyong
Copy link
Contributor Author

mouyong commented Dec 15, 2022

hello, in my app, use fpm, it can successful, in workerman, it run failed. i can't know different before php-fpm and workerman cli. I already fix a application error. now it can run in php-fpm mode.

@joanhey joanhey added the wontfix This will not be worked on label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants