PHP Classes

File: test/test_big_excel_file.php

Recommend this page to a friend!
  Classes of Ionut-Alexandru Toma   PHP Export Data   test/test_big_excel_file.php   Download  
File: test/test_big_excel_file.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Export Data
Export data in CSV, TSV, or Excel XML formats
Author: By
Last change:
Date: 6 years ago
Size: 820 bytes
 

Contents

Class file image Download
<?php

// Example of exporting a large amount of data to a file. On my
// computer it takes 43 seconds to write out 83MB of data, but
// only uses 750kb of memory.

require "../php-export-data.class.php";

function
genRandomString($length = 100) {
   
$characters = "0123456789abcdefghijklmnopqrstuvwxyz _";
   
$string = "";
    for (
$p = 0; $p < $length; $p++) {
       
$string .= $characters[mt_rand(0, strlen($characters)-1)];
    }
    return
$string;
}

$excel = new ExportDataExcel('file');
$excel->filename = "test_big_excel.xls";

$excel->initialize();
for(
$i = 1; $i<100000; $i++) {
   
$row = array($i, genRandomString(), genRandomString(), genRandomString(), genRandomString(), genRandomString());
   
$excel->addRow($row);
}
$excel->finalize();


print
"memory used: " . number_format(memory_get_peak_usage());