Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shakogele's avatar

Maatwebsite Excel Export : my_site is currently unable to handle this request.

Hello,

I've integrated Maatwebsite plugin for Exel exports. When I'm exporting a small amount of data for eg. 2000 rows its working just fine, but when I export more than 2000 rows website gets stuck and in chrome I get

The my_site page isn’t working

my_site is currently unable to handle this request. HTTP ERROR 500

I've increased max_execution_time also memory_limit in php.ini file, also I've checked log files and nothing is in there.

can somebody help me with this issue?

thanks

0 likes
12 replies
Snapey's avatar

nothing in the apache /nginx logs?

shakogele's avatar

I've just seen these log in apache logs

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in /home/admin/..../public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 347, referer: http://some.url

jimmck's avatar

PHPExcel creates the spreadsheet in memory as a default. So the number or rows and/or columns places a constraint on the size. Maatweb is a wrapper on top of PHPExcel, I don't know if it supports the filter options. Also can you free any result sets or other objects as you build the spreadsheet?

1 like
shakogele's avatar

I have a functions that generates data objects (each object contains 18-20 parameters - columns):

$data1 = $this->getPhysicalCustomersData($request->createdat_from, $request->createdat_to, $filter_vars); $data2 = $this->getCorporateCustomersData($request->createdat_from, $request->createdat_to, $filter_vars);

than I am passing these variables as closure to Excel:

Excel::create('Customers'.date('h-i-s, j-m-y', $_SERVER['REQUEST_TIME']), function($excel) use($data1, $data2) { $excel->sheet('physical customers', function($sheet) use($data1) { $sheet->fromArray($data1); }); $excel->sheet('Corporate customers', function($sheet) use($data2) { $sheet->fromArray($data2); }); })->export('xlsx');

what should I clear, or Am I doing something wrong?

Snapey's avatar

If you are doing a sql query per row (and check if you are or not) you can run into memory problems with the sql query logging which seems to be on by default.

Run this immediately before your processing

    \DB::connection()->disableQueryLog();
1 like
shakogele's avatar

I've tried but the error still occurs,

I' have 25 columns in each row, when I try 5 -7 (and remove other columns) columns it is working

this is my code

$phos = $phos->get();
    $data = [];
    $val=[];
    foreach($phos as $co){

      $val['PHDescription']               = $co->label;
      $val['Physical_ID']                 = $co->physical_id;
      $val['PH_Contact']                  = $co->contacts->first_name ." ".$co->contacts->last_name;
      $val['PH_Mobile']                   = $co->contacts->mobile;
      $val['PH_Phone']                    = $co->contacts->phone;
      $val['PH_Email']                    = $co->contacts->email;
      $val['PH_Address']                  = $co->addresses->address;
      $val['PH_City']                     = $co->addresses->cities->name;
      $val['PH_Region']                   = $co->addresses->cities->regions->name;
      $val['Customer_Antena']             = $co->customers->antenas->name;
      $val['Customer_Panel']              = $co->customers->antenas->panels->name;
      $val['Customer_Station']            = $co->customers->antenas->panels->stations->name;
      $val['Customer_CompanyRouter']      = $co->customers->companyrouters->name;
      $val['Customer_IP']                 = $co->customers->companyrouterips->ipaddress;
      $val['Customer_Packets']            = $co->customers->packets->name;
      $val['Customer_Status']             = $co->customers->accountstatuses->status;
      $val['Customer_MacAddress']         = $co->customers->mac_address;
      $val['Customer_AntenaOwner']        = $co->customers->antena_owner;
      $val['Customer_AntenaInsured']      = $co->customers->insured;
      $val['Customer_CreatedAt']          = $co->customers->created_at;
      $val['Customer_UdpatedAt']          = $co->customers->updated_at;
      $val['Account_Cash']                = $co->customers->cashBalance();
      $val['Antena_Insurance_Cash']       = $co->customers->antenaInsuranceCash();
      $val['Antena_Rent_Cash']            = $co->customers->antenaRentCash();
      $val['Account_Debt']                = $co->customers->debt();

      $data[] = $val;
    }

shakogele's avatar

When I dd($phos) before this code it shows me all the data, but inside the code abobe it gets stuck.

jimmck's avatar

20 columns x 2000+ rows = Lots Of Memory. You can't create spreadsheets that big without paging.

https://blog.mayflower.de/561-Import-and-export-data-using-PHPExcel.html

http://stackoverflow.com/questions/16667376/phpexcel-memory-still-exhausted-even-with-cell-caching-other-solutions

http://code-usage.com/v/PHPExcel_Settings:setCacheStorageMethod

Of course there are reports of it not working at all

https://github.com/PHPOffice/PHPExcel/issues/415

You are going to have to research this a bit.

PHPExcel can read large files but I do not rely on it for writing large files.

And you can make your PHP memory size as big as you want. Get to many calls to your webserver making large xls files and you will crash your server.

Resource management is crucial at all points and Laravel magic will not do that for you.

1 like
shakogele's avatar

this was a solution for me:

    $count = $phos->count();
    $off_ex = 1000;
    for($j = 0;$j < $count/$off_ex;$j++){

      $phoss = $phos->skip($j*$off_ex)->take($off_ex)->get();

      foreach($phoss as $co){

        $val['Customer_Antena']             = $co->customers->antenas->name;
        $val['Customer_Panel']              = $co->customers->antenas->panels->name;
        $val['Customer_Station']            = $co->customers->antenas->panels->stations->name;
        $val['Customer_CompanyRouter']      = $co->customers->companyrouters->name;
        $val['Customer_IP']                 = $co->customers->companyrouterips->ipaddress;
        $val['Customer_Packets']            = $co->customers->packets->name;
        $val['Customer_Status']             = $co->customers->accountstatuses->status;
        $val['Customer_MacAddress']         = $co->customers->mac_address;
        $val['Customer_AntenaOwner']        = $co->customers->antena_owner;
        $val['Customer_AntenaInsured']      = $co->customers->insured;
        $val['Customer_CreatedAt']          = $co->customers->created_at;
        $val['Customer_UdpatedAt']          = $co->customers->updated_at;
        $val['Account_Cash']                = $co->customers->cashBalance();
        $val['Antena_Insurance_Cash']       = $co->customers->antenaInsuranceCash();
        $val['Antena_Rent_Cash']            = $co->customers->antenaRentCash();
        $val['Account_Debt']                = $co->customers->debt();

        $data[] = $val;

      }


Snapey's avatar

You should definitely look at eager loading those related models, or using a join.

Please or to participate in this conversation.