process a huge excel file with php

102 views Asked by At

i'm working with a huge excel file with 5500 rows and 50 column, processing just 100 rows need more than one minute to have the display and i can't process whole the file i still waiting more than 6 minutes without any result, i tried to use cached methods ( i don't have big knowledge for this kind of methods you will see my try below) it works with the 100 rows but of course at the first time i waited the one minute and after that i get my datas instantly, and alwyas i can't process my huge file. this is my try :

<?php
    require_once ".\Classes\PHPExcel\IOFactory.php";
    $objPHPExcel = PHPExcel_IOFactory::load("zfg01_CAT.xlsx");
    $sheet = $objPHPExcel->getSheet(0);
    include 'fonctionsUtiles.php';
    $cache = 'cache/index.html';
    $expire = time() - 3600; // valable une heure

    if (file_exists($cache) && filemtime($cache) > $expire) {
        readfile($cache);
    } else {
        ob_start(); // ouverture du tampon

        afficherUneFeuille($sheet);
        echo'<br>';
        echo $sheet->getHighestRow();
        echo'<br>';

        supprimerLesDoublons($sheet);
        afficherUneFeuille($sheet);
        echo $sheet->getHighestRow();
        echo'<br>';
        $page = ob_get_contents(); // copie du contenu du tampon dans une chaîne
        ob_end_clean(); // effacement du contenu du tampon et arrêt de son fonctionnement

        file_put_contents($cache, $page); // on écrit la chaîne précédemment récupérée ($page) dans un fichier ($cache) 
        echo $page; // on affiche notre page :D 
    }
    ?>

Thanks for your help sorry for my bad english ^^

1

There are 1 answers

0
Adrien On

You can try using Spout: https://github.com/box/spout. Using it is straightforward and it supports very large files without requiring any changes to php.ini nor caching techniques.