简体   繁体   中英

Is there any PHP performance issue in export to CSV or excel

am exporting huge data to excel using php.

i change that to csv and text.

i see no difference in file size.

So PHP performance have anything to do with file format.

even if file format is different , rows and columns is same. consider 60 column and 100000 rows.

is there any optimizing technique,other than ini memory limit and execution time. we have to taken care

As far as I know, the various Excel libraries for PHP will build the spreadsheet in-memory, which could cause problems for very large data sets. CSV/txt, on the other hand, can be written out to disk or the client for each row, so memory usage is minimal.

Performance-wise, the Excel libraries will always have larger overhead. There's all kinds of extra Excel-specific binary bits in the file which need special handling in PHP, whereas CSV is just plain text. PHP's core purpose is to be able to spit out large amounts of text very quickly, so generating csv/txt is going to be faster, always. And of course, there's function call over head. In pseudo code, consider the difference between:

CSV:

echo "$column1, $column2, $column3, $column4";

versus Excel:

$workbook->write('A1', $column1);
$workbook->write('B1', $column2);
$workbook->write('C1', $column3);
$workbook->write('D1', $column3);

etc...

On the plus side for Excel, particularly with XLSX, there is some compression so the same amount of data will take up less space. This can be mitigated somewhat by using compression in the webserver, or feeding the CSV/txt output into a Zip library server-side.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM