My VPS has 8GB memory
When I try to write 4000 Rows and 62 Columns. 1 column has an image (PHPExcel_Worksheet_MemoryDrawing)
After writing some data OS has kill background script because VPS has not had more memory.
I'm using PHPExcel version 1.7.8
I have writing excel file in each loop.
Image write sample code
$gdImage = imagecreatefromstring(file_get_contents($proof_photo_1));
if ($gdImage) {
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setImageResource($gdImage);
$objDrawing->setCoordinates("BA" . $i);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing->setHeight(150);
$width = $objDrawing->getWidth() * 0.143;
$height = $objDrawing->getHeight() * 0.75;
if ($rowDim->getRowHeight() < $height) {
$rowDim->setRowHeight($height);
}
$colDimSh = $objPHPExcel->getActiveSheet()->getColumnDimension("BA");
$colDimSh->setAutoSize(false);
$colDim = $objPHPExcel->getActiveSheet()->getColumnDimension("BA");
if ($colDim->getWidth() < $width) {
$colDim->setWidth($width);
}
unset($objDrawing);
} else {
$objPHPExcel->getActiveSheet()->SetCellValue("BA" . $i, "-");
}
I have tried many things to save memory
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array('memoryCacheSize' => '100MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);
In side each loop
if($i % 100 == 0){
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($csvPath);
$objPHPExcel->disconnectWorksheets();
unset($objWriter);
unset($objPHPExcel);
chmod($csvPath, 0777);
$objPHPExcel = PHPExcel_IOFactory::load($csvPath);
$objPHPExcel->setActiveSheetIndex(0);
}
Above take much time for write excel file and sometimes file reset from begaing.