swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.04k stars 390 forks source link

Laravel Localization with swoole #441

Closed mrmarchone closed 3 years ago

mrmarchone commented 4 years ago

Hello i installed the package named mcamara for localization and put it's middlewares in kernel.php , it's working when i serve from php artisan serve, but when serve from php artisan swoole:http start it's not working ? Why ?

Arkanius commented 4 years ago

What's your output?

Swoole runs in an asynchronous way, so, basically, your entire framework will be loaded in your RAM just once and you will be the responsable to clear all the instances that you could be using. By your (short) description, I think that your location is cached at first request and being shared to the others resquest.

Please, make sure that you're doing the right cleaning of your instances.

Check your config/swoole_http.php file and try to make use of instances array

Gemui commented 4 years ago

i have the same problem with laravel translatable package that use mcamara package problem is any route have translatable middleware redirect to APP_URL/lang example domain.com/dashboard => domain.com/en it's should redirect to => domain.com/en/dashboard this issue only with swoole server

my nginx configuration

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
server {
    listen 80;
    server_name forera.develop;
    root /var/www/html/forera/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    add_header Vary "Accept-Language";

    index index.php;

    charset utf-8;

    location / {
        # try_files $uri $uri/ /index.php?$query_string;
                try_files /not_exists @swoole;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
      location @swoole {
        set $suffix "";

        if ($uri = /index.php) {
            set $suffix ?$query_string;
        }

        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    proxy_set_header Vary Accept-Language;
        # IF https
        # proxy_set_header HTTPS "on";

        proxy_pass http://127.0.0.1:1215$suffix;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
    }

it's working perfect with the same configuration but change proxy_pass to laravel serve => 127.0.0.1:8000

Arkanius commented 4 years ago

Are your middleware being reached?

Gemui commented 4 years ago

yes middleware is => LocaleSessionRedirect

it's depend on LaravelLocalization

Arkanius commented 4 years ago

Hum, got it. I'll try to reproduce it

Gemui commented 4 years ago

@Arkanius any updates ?

Arkanius commented 4 years ago

not yet. I didn't get time to try =/

Gemui commented 4 years ago

i will try with it, just tell me from where i should start debug Like (files responsible of this redirection, middleware, ...)

Arkanius commented 4 years ago

Well, the first thing I'd debug is if your middleware is being reached. Try to check the follow:

  1. Is your middleware (LocaleSessionRedirect) being created and destroyed at every request?
  2. If the redirect of (LocaleSessionRedirect) isn't working, which is the if that is making your condition fail?