Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
Can't import excel with 2 millions rows mysql laravel?

I can't import mysql data with 2 million rows at the moment I can only import 8500 data.If I am over 8500 it will appear

" 503 Service Unavailable The server is temporarily busy, try again later! "

enter image description here

<?php

namespace App\Imports;
use App\Models\{Datalead,Debitur,Perusahaan,Saldolist};


use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\{ToCollection, WithHeadingRow, WithCalculatedFormulas,WithMultipleSheets };

class DataleadImportSaldolist implements ToCollection, WithHeadingRow, WithCalculatedFormulas,WithMultipleSheets 
{
    /**
    * @param Collection $collection
    */

    public function sheets(): array
    {
        return [
            0 => $this,
        ];
    }
    public function collection(Collection $collection)
    {
        //print("<pre>".print_r($collection,true)."</pre>");
        foreach ($collection as $row) 
        {

                    $saldo = Saldo::create([

                        'Tanggal' => $row['tanggal'],
                        'KodeCab' => $row['kode_cab'],
                        'NamaCab' => $row['nama_cab'],
                        'KodeKLN' =>$row['kodekln'],
                        'SentraKode'=> $row['sentra_code'],
                        'KodeKCP' => $row['kodekcp'],
                        'AccountType' => $row['account_type'],
                        'SubCategory' => $row['sub_category'],
                        'Produk' => $row['produk'],
                        'Peruntukan' => $row['peruntukan'],
                        'Currency' =>  $row['currency'],
                        'Kurs' => $row['kurs'],

                    ]);
        }        
    }
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As I see you using a foreach loop, maybe it's a good thing to read up on how to use less memory looping over huge sets of data in Laravel.

This is a great article: https://blackdeerdev.com/laravel-chunk-vs-cursor/

In short: the chunk function could keep memory usage low. Also you can increase the max exececution time for PHP

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda