Laravel-swoole: paginate issue

Created on 5 May 2018  路  25Comments  路  Source: swooletw/laravel-swoole

i just started using swoole in laravel 5.6 but paginate is not working

plz check

https://celebpix.net/

not enough info question

All 25 comments

Please provide more detail about your question, thanks.

Hi @deepakSP ,

Can you please read Issues Guideline and then try to describe your issue more specifically?

Otherwise I have no clues how I can help you, thanks.

ok few things i solved the issue
1 . i was setting request variable in controller construct and that seems to create problem.
eg.

public function __construct() {
    $this->page = request('page', 1)
}

output of $this->page was always 1

  1. i think nginx config needs 1 change (at-least for me this change worked)
    i was not getting request data in home pages

    if ($uri = /index.php) {
        set $suffix "/?$args"; # added $args for request ??
    }
    

let me know what you think about nginx config !

Ok, here is the problem:

public function __construct() {
    $this->page = request('page', 1)
}

Since each controller class will be resolved only in the first time. So you can't set page in the constructor. You have to get it in each separate function.

There's one important concept: Your laravel application is stored in memory after you use this package. So you have to reset or recycle those variables by yourself. In traditional PHP-FPM, all your resource will be destroyed after request process is done. Developers don't need to care about if their class or variable effects the next request. Now it matters.

yes i understand now, little new for me.
what about nginx config ?

Well, I think you don't need to make that change on Nginx config. If you get page parameter in each function, you should be able to see the correct result.

no its not working without that change.

What's your access url? Actually you can ignore that part because unless you access your app with url: http://yourweb.site/index.php or that section will not take effect.

https://celebpix.net/

I didn't meant website not working only i cant get request('page') for pages which has pagination interestingly search was working fine (i was able to get request('q') for search page ).

if you want i can updated nginx to old conf.

I've tested on my side with the same Nginx config, and it works properly.

Maybe you can try to dump request()->all() first to check if you can get all the query parameters.

old-conf

nope not working..
one more thing i am using docker !

Ok, I think we can make things simpler. Does it work if it's not behind Nginx proxy? If it only happens behind Nginx, you can paste your Nginx config for reference.

Yes its work when not in nginx proxy

one more thing can you add how to run in background notes.
i am using supervisor but its not able to stop gracefully .. here is my conf for supervisor

[program:laravel-swoole]
process_name=%(program_name)s_%(process_num)02d
command=docker exec php php /path/to/artisan swoole:http start
autostart=true
autorestart=true
user=root
stopsignal=KILL
killasgroup=true
redirect_stderr=true
stdout_logfile=/var/logs/worker.log

Hi @deepakSP ,

So can you provide your Nginx config for reference?

And in fact you can run swoole server in daemon mode by setting your .env

SWOOLE_HTTP_DAEMONIZE=true

oh yes i found that to

here is my nginx config file ..

`
server {
listen 80;
index index.php index.html;

server_name example.com;

root /data/code/example.com/public;


keepalive_timeout 10;

location = /index.php {
     try_files /not_exists @swoole;
}

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


location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php;
    fastcgi_index index.php;
    fastcgi_keep_conn on;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
}

location @swoole {
    set $suffix "";

    if ($uri = /index.php) {
        #set $suffix "/";
        set $suffix "/?$args";
    }
    proxy_set_header Connection "keep-alive";
    proxy_set_header Host $host;
    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_http_version 1.1;
    proxy_set_header Connection "";
    #proxy_set_header Connection $connection_upgrade; - was throuwing error so have to disable it
    # IF https
    # proxy_set_header HTTPS "on";
    proxy_pass http://127.0.0.1:1215$suffix;
}


error_log  /var/logs/error.log;
access_log /var/logs/access.log;

}

`

Hi @deepakSP ,

FYI, in the newest release, I've made it clean resolved controller on every request. You can check it with your previous code.

As for the Nginx config, because I'm working on other issues, I will leave it here for a while.

ok cool .. thanks 馃憤

this issue started again in update

this time request is fine but every page showing page 1 data.

eg.

for - ?page=1
Post::paginate(10);

output - page 1 data

for - ?page=2
Post::paginate(10);

output - page 1 data

expected output - page 2 data

also there is log issue. it caches first error and displays same error every time there is some error even when it should not

Need help


map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen          80;
    server_name     demo.com;
    charset         utf-8;
    root            /sites/demo/public;

    gzip on;
    gzip_static on;
    gzip_http_version 1.0;
    gzip_disable "MSIE [1-6].";
    gzip_vary on;
    gzip_comp_level 9;
    gzip_proxied any;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;

    fastcgi_intercept_errors off;
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_read_timeout 180;

    # Remove trailing slashes
    rewrite ^/(.*)/$ /$1 permanent;

    access_log  /sites/demo/storage/logs/default.access.log;

    location = /index.php {
        # Ensure that there is no such file named "not_exists"
        # in your "public" directory.
        try_files /not_exists @swoole;
    }


    location / {
        try_files $uri $uri/ @swoole;
        #$try_files $uri $uri/ /index.php?$args;
####$        index  index.php;
####$        autoindex   on;
####$        include  /usr/local/etc/nginx/php-fpm;
####$        add_header 'Access-Control-Allow-Origin' 'http://app.com';
####$        add_header 'Access-Control-Allow-Credentials' 'true';
####$        add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, PUT, OPTIONS';
####$        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-XSRF-TOKEN,X-CSRF-TOKEN,Origin';
    }

    location @swoole {
        set $suffix "";

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

        proxy_set_header Connection "keep-alive";
        proxy_set_header Host $host;
        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_http_version 1.1;
        proxy_set_header Connection "";
        #proxy_set_header Connection $connection_upgrade; - was throuwing error so have to disable it
        # IF https
        # proxy_set_header HTTPS "on";
        proxy_pass http://127.0.0.1:1215$suffix;
    }

    location ~ /\.ht {
        access_log off;
        log_not_found off;
        deny all;
    }

    location ~* \.ico$ {
        expires 1w;
        access_log off;
    }

    location ~* \.(?:jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm)$ {
        try_files $uri $uri/ /index.php?$query_string;

        access_log off;
        log_not_found off;
    }

    location ~* \.(?:css|js)$ {
        try_files $uri $uri/ /index.php?$query_string;
        access_log off;
        log_not_found off;
    }

    client_max_body_size 512M;

    add_header "X-UA-Compatible" "IE=Edge,chrome=1";
}

Hi @deepakSP ,

Thanks for reporting pagination issues, this is caused by dirty app binding in PaginationServiceProvider:

Paginator::currentPageResolver(function ($pageName = 'page') {
            $page = $this->app['request']->input($pageName);

            if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
                return (int) $page;
            }

            return 1;
        });
    }

I'm trying to fix it.

As for the log, can you fix that by adding log to instances in swoole_http.php?

Hi @olivia-outshine ,

Is your comment related to this issue topic? I just can't find any clues how I can help you. Please read Issues Guideline and open another issue for your question, thanks.

thanks @albertcht for working so hard but for now i have disabled in production, once you update i will test in local environment.

Hi @deepakSP ,

In the release v2.3.7 pagination issue should be fixed. You can go check it.

And I don't quite understand about your log issues. Can you provide more detail about that?

Was this page helpful?
0 / 5 - 0 ratings