I am trying to import excel data into database using PHP excel Library.It is working for small amount of data.For large data (30000 rows) it is not working.It is taking much time.
here is my code
$fileName = $_FILES["production"]["tmp_name"];
$objPHPExcel = PHPExcel_IOFactory::load($fileName);
$phpspreadsheet = $objPHPExcel->getSheet(0);
$total_data = $phpspreadsheet->getHighestRow();
//echo $chunkSize;
// exit;
$highest_column = $phpspreadsheet->getHighestColumn();
for ($row = 2 ; $row <= $total_data; $row++) {
$productionDataAll = $phpspreadsheet-> rangeToArray ('A' . $row . ':' . $highest_column . $row, NULL, TRUE, FALSE);
$line=htmlentities($productionDataAll[0][0]);
$workedorder=htmlentities($productionDataAll[0][1]);
$modelnumber=htmlentities($productionDataAll[0][2]);
$revision=htmlentities($productionDataAll[0][3]);
if(!empty($productionDataAll[0][4])){
$serialnumber=htmlentities($productionDataAll[0][4]);
}
else{
$serialnumber='';
}
$lpn=htmlentities($productionDataAll[0][5]);
$shift=htmlentities($productionDataAll[0][6]);
$datecreated=htmlentities($productionDataAll[0][7]);
$datecompleted=htmlentities($productionDataAll[0][8]);
$repairflag=htmlentities($productionDataAll[0][9]);
$date=date("Y-m-d", strtotime( '-1 days' ) );
$skeydate=date("Ymd", strtotime( '-1 days' ) );
$skey=$skeydate.$line;
$importproduction=importproduction($mysql_connectionLinkLocal,$line,$workedorder,$modelnumber,$revision,$serialnumber,$lpn,$shift,$repairflag,$date,$skey,$datecreated,$datecompleted); // insert function
}
above code is reading sheet data one by one and inserting into database. How to read the sheet data by 100 (chunck)? How to reduce the loading time?I am getting page unresponsive
Try https://github.com/aVadim483/fast-excel-reader
It can read excel data very quickly and with minimal memory usage (but XLSX format only). There is example with reading of 100K spreadsheet in demo folder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.