Eloquent giving 500 error with many results [closed]

0

I'm doing a query in my database with some LEFT JOIN and some WHERE clauses, however, I'm having a lot of difficulties regarding the return of this query, which, having many results, simply after a certain processing time gives 500 error For example:

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

In this case, there is a need for the customer to return data for up to 60 days and the way it is, it 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()
    
asked by anonymous 26.01.2016 / 16:20

1 answer

1
  

RESOLVED

     

Personally, I have been able 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, that is, just create a Command in Laravel and inform which script and it would execute from behind. I created a .sh file for this routine.

     

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

    
28.01.2016 / 18:33