0

I am trying to upload excel sheet in laravel with the help of laravel excel package. The problem i am facing is that, even after following their instructions when i try to upload my excel sheet it keeps loading and loading. On the laravel log file it says that

 local.ERROR: Out of memory (allocated 1598029824) (tried to allocate 469762048 bytes) {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1)

The file size is only 70kb and on my php.ini i have allocated 8gb memory

The code that i am using to read the excel file is below

 if($request->hasFile('excelSheet')){
            $path= $request->file('excelSheet')->getRealPath();
            $data = \Excel::selectSheetsByIndex(0)->load($path)->get();
            echo'<pre>';
            print_r($data);
        }

The excel sheet that i am trying to upload has multiple sheet, a screenshot of which is been attached with the question. Can anyone please tell me how i can get these data or how can i fix memory allocation problem ? Excel sheet image

user7747472
  • 1,874
  • 6
  • 36
  • 80
  • Then I would suggest that PHP has not picked up your change to 8Gb as its failing trying to allocate a bit more that 1.5Gb. Are you sure you changed the correct `php.ini` file AND restarted your web server – RiggsFolly Mar 10 '18 at 21:33
  • `1598029824` !== 8GB – Mark Baker Mar 10 '18 at 21:39
  • But filesize of a spreadsheet is no indication of its memory requirements; the number of cells (across all worksheets that you're loading) is far more significant – Mark Baker Mar 10 '18 at 21:41
  • PS: `phpExcel` has been replaced by `phpSpreadsheet`. I think its by the same guy, so one has to assume he has made `phpSpreadsheet` bigger, better and more wonderful – RiggsFolly Mar 10 '18 at 22:05
  • Have you tries to make it without your Excel package ? just with the `$csv = file($request->file('excel'));` ? – kevinniel Mar 10 '18 at 22:11
  • If you are only trying to read data from the file or write data to a new file, you might try Box's spout package, instead. You don't get the nice file manipulation that you do with phpSpreadsheet, but it's a much lighter for RAM footprint: http://opensource.box.com/spout/getting-started/ – pft221 Mar 10 '18 at 23:19
  • Are you using php-fpm? Try restarting that if so. Also check you max_post_size in php.ini. –  Mar 10 '18 at 23:37
  • @RiggsFolly yes the changes has been committed, and accepted by php too. I tried with another file in core php of size 1.2gb that worked perfectly fine, and i am sorry. i do not understand what your second comment means – user7747472 Mar 11 '18 at 05:05
  • @MarkBaker yes, 1598029824 !== 8GB might be right but but for a file size 70kb should not be needing that much memory. I made that changes to upload a file of 3GB that in core php ofrcourse. this is first time trying in laravel, "filesize of a spreadsheet is no indication of its memory requirements ", yes you might be right about that. But this one has about 30 cells for each row . so it should not be needing that much of memory i am guessing its going in a loop or something – user7747472 Mar 11 '18 at 05:07
  • @btl yes, my max_post_size is also 8gb, – user7747472 Mar 11 '18 at 05:08
  • 30 cells for each row? How many rows? Is it the same on each of the 3 worksheets? Going into a loop? Possible, but unlikely.... but I shall immediately investigate the possibility that there may possibly be a bug in the 250k lines of code that makes up PHPExcel that may put the code into a loop when something that may be in some spreadsheet file triggers it – Mark Baker Mar 11 '18 at 11:28
  • @MarkBaker yes about 30 cell per row, and for now i have only 13 row in sheet1, i am only fetching data from sheet 1, remaining sheet i don't need .Those are only for field validation of excel sheet – user7747472 Mar 11 '18 at 12:08

0 Answers0