PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Laravel 502 Proxy Error on specific route call

 February 17, 2022     http-status-code-502, laravel, laravel-5     No comments   

Issue

I am having a problem specific to the production code. On said server, everytime I try to access specific route which is supposed to show a table of all categories I get a 502 Proxy Error:

Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: Error reading from remote server

I have found some common problem on the internet already, however all of those were for users who use nginx. I use Laragon. Also, Laravel version is 5.5.21

As I said the problem is production code only. It is not happening when I run it locally.

I also tried to download laravel.log file from the server, but there was nothing there.

This is the function that is being called by route:

public function index(){
        if(empty(request()->query()) && session()->exists('categories_filter')){
            return redirect(route('categories.index').'?'.http_build_query(session()->pull('categories_filter')));
        }

        if(!empty(request()->query())){
            $this->store_filter();
        }

        $categories = Category::orderBy($this->sort, $this->order);

        if($name_sk = request('name_sk')){
            $categories = $categories->where('name_sk', 'like', "%{$name_sk}%");
        }

        $categories = $categories->paginate(20);
        $all_categories = Category::with('children')->get();

        $sort = $this->sort;
        $order = $this->order;
        $new_order = $this->new_order;

        return view('admin.categories.index', compact('categories', 'sort', 'order', 'new_order', 'all_categories'));
    }

I honestly have no idea where the problem lies or what is its cause.


Solution

So to the people who have a similar problem, here is where my problem was:

I had a recursive blade partial component, that called itself and in every single one of those there was a sql query executed. I had to completely remake that part of my view.

So to explain it, the reason for this error is simply that I was sending too many requests to the database asking for a single row. This was a problem because once there was a moderate amount of data, it was simply taking way too long to load.



Answered By - Lukas Grofcik
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing