Eloquent giving error 500 with many results

Asked

Viewed 174 times

0

I’m performing a query in my base with some LEFT JOIN and some WHERE clauses, however, I’m having a lot of difficulties with the return of this query that, for having many results, simply after a certain processing time gives error 500. For example:

  • I did the query and ran it returning only 1 result - it worked;
  • I made the query returning a short time (5 days only) with about 9 thousand records - It worked;
  • I made the query with 15 days, return approximately 30 thousand records - Does not work, gives error 500.
  • I made the consultation with 14 days, returned about 28 thousand records - It worked O.o

In this case, there is the need, on the part of the client to return data up to 60 days and the way it is, does not work.

Follow the query:

$this->clientes->select('clientes.id', 'clientes.nome', 'clientes.email', 'clientes.created_at',
            'clientes.updated_at AS ultima_atualizacao', 'origem.titulo AS titulo_origem',
            'clientes.sexo', 'produtos.nome AS nome_produto', 'clientes.tipo_logradouro',
            'clientes.telefone1', 'clientes.telefone2', 'clientes.telefone3',
            'clientes.logradouro', 'clientes.numero', 'clientes.complemento', 'clientes.bairro',
            'clientes.cidade', 'clientes.estado', 'clientes.cep', 'clientes.status',
            'usuarios.susep_principal', 
            'produto_auto_veiculo.marca', 'produto_auto_veiculo.modelo', 'produto_auto_veiculo.ano_fabricacao',
            'produto_auto_veiculo.ano_modelo', 'atendimento_cliente.hora_vinculo',
            'atendimento_cliente.created_at AS ultimo_contato')
        ->leftJoin('atendimento_cliente', 'clientes.id', '=', 'atendimento_cliente.id_cliente')
        ->leftJoin('produtos', 'produtos.id', '=', 'atendimento_cliente.id_produto')
        ->leftJoin('origem', 'origem.id', '=', 'clientes.id_origem')
        ->leftJoin('usuarios', 'usuarios.id', '=', 'clientes.id_corretor')
        ->leftJoin('pedidos', 'usuarios.id', '=', 'pedidos.id_cliente')
        ->leftJoin('produto_auto_veiculo', 'produto_auto_veiculo.pedido_id', '=', 'pedidos.id')
        ->orderBy('clientes.' . $inputs['ordem'], 'desc')
        ->groupBy('clientes.id')
        ->get()
  • Where is the Where ?

  • 1

    There is a method that Implements the WHERE if is requested. Look an example: ->where('estado', $this->inputs['name_search']);, but it isn’t obligatory on query, just is called if a request is Filtered. In this example, I have the same problem, if I Return one data with first() of eloquent, it Works, but if I Return with get() Give 500 error.

  • I speak Portuguese, I just made a joke using the where. There is nothing wrong when you choose 15 days to make the query ? Your file config.php in the briefcase app is with debug => true ?

  • What is the specific error? error 500 is Generico does not say what is the root of the problem.

  • Probably memory exhaustion. For these things not to occur, I always use paging. If applicable, implement Infinite scroll in your application.

  • Two problems, the first is that it simply does not present the error itself, only error 500. Debug enabled, native error screen rendering Ok, made tests on other pages simulating error 500 working, but only in this case returns nothing. I checked Laravel’s log, and I also got no response to the error. Regarding pagination, I cannot use, this data is necessary to generate a CSV. ;(

  • 2

    You must separate the answer part of the question, after a few minutes accepted the answer(green light), means that the problem has been solved.

Show 2 more comments

1 answer

1


RESOLVED

Guys, I managed to solve the problem, in quotes, but it meets the needs of the company. I already had an interface to implement several reports through script, IE, just create a Command in Laravel and inform which script and it would run from behind. I created a file .sh for this routine.

As for the problem, it was not specifically the case in the Eloquent, but in PHP itself that did not support the amount of data, I was able from my personal machine to debug the code and identified that when the result was placed inside an array, up to a certain amount worked, however, at one point, blew the server memory.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.