0

I have 2 functions to parse each one a file Excel their sizes are 673K and 131K. They have the same code just their names. One function it read the data from file Excel and the other function it return:

Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (Tried to allow 72 bytes)

I have others files Excel their sizes more bigger than this ones and their parsing functions works well.

I want to create a logfile to register every action they do inside the system but I have no idea how to do it. On the other hand I found this solution in Stackoverflow for @Lawrence Cherone: enter link description here

But the problem is the first time I will do a logfile, I don't know how I create it ? I create a new file and I put it in my project ? How I excute it and how I can see the reason of the error in my function ? Or I put this file in the function when I have the error like the solution proposed by @Lawrence Cherone ? This solution it seems worked fine and the problem is resolved. This following is my small code of my function, can you guide me how I create this logfile to debug it:

public function parseEquipment($filePath = null) {
        set_time_limit(0);
        $listEquipement = [];       
        $count = 0;
        $chunkSize = 1024;
        $objReader = PHPExcel_IOFactory::createReader(PHPExcel_IOFactory::identify($filePath));
        $spreadsheetInfo = $objReader->listWorksheetInfo($filePath);
        $chunkFilter = new \Floose\Parse\ChunkReadFilter();
        $objReader->setReadFilter($chunkFilter);
        $objReader->setReadDataOnly(true);
        $chunkFilter->setRows(0, 1);
        $objPHPExcel = $objReader->load($filePath);
        $totalRows = $spreadsheetInfo[0]['totalRows'];
        for ($startRow = 1; $startRow <= $totalRows; $startRow += $chunkSize) {
            $chunkFilter->setRows($startRow, $chunkSize);
            $objPHPExcel = $objReader->load($filePath);
            $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, null, true, false);
            $startIndex = ($startRow == 1) ? $startRow : $startRow - 1;

            if (!empty($sheetData) && $startRow < $totalRows) {             
                $dataToAnalyse = array_slice($sheetData, $startIndex, $chunkSize);
                //echo 'test1'; 
                if($dataToAnalyse[1][0]==NULL){
                    //echo 'test2';
                    break;
                }

                //echo 'test3';
                //var_dump($sheetData);
                for ($i = 0; $i < $chunkSize; $i++) {
                    if ($dataToAnalyse[$i]['0'] != NULL) {
                        //echo 'OK';
                        $listEquipement[] = new Article($dataToAnalyse[$i]['3'], $dataToAnalyse[$i]['4'], $dataToAnalyse[$i]['2']);
                    //   echo 'test4';                      
                        $count++;
                        }
                }
            }
            $objPHPExcel->disconnectWorksheets();
            unset($objPHPExcel, $sheetData);
        }   

        //var_dump(array_slice($sheetData, $startIndex, $chunkSize););
        return $listEquipement; 
    }
Community
  • 1
  • 1
Nazly
  • 65
  • 10

1 Answers1

0
error_log("You messed up!".$my_message, 3, "/var/tmp/custom-errors.log");
mujuonly
  • 11,370
  • 5
  • 45
  • 75