Bonjour,
voilà mon soucis j'ai codé un eport de ma database en fichier xls, pour cela j'ai utilisé la blibiothèque LaravelExcel. Le problème est qu'en local l'execution ce fait comme il faut et je peux télécharger mon fichier mais sur mon serveur, quand j'apelle ma fonction j'ai une page d'erreur avec "Document non trouvé".
J'ai essayé avec une autre blibliothèque qui est PhpExcel, le même problème, marche en local mais pas sur le serveur de production.
Voici le code avec LaravelExcel:

$data = $this->repository->getDatabase();
        $fichier = Excel::create('export_Satiscope_'.date('d-m-Y'),function($excel) use($data){
            $excel->sheet('Sheet 1',function($sheet) use($data){
                $sheet->fromArray($data);
            });
        })->export('xls');

Et voici le code avec php Excel :

 $classeur = new \PHPExcel();
    $classeur->getProperties()->setCreator("Moi");
    $classeur->setActiveSheetIndex(0);
    $feuille=$classeur->getActiveSheet();
    $i = 0;
    $feuille->setTitle('Satiscope');

    $feuille->setCellValueByColumnAndRow(0, 1, 'fullname');
    $feuille->setCellValueByColumnAndRow(1, 1, 'phone');
    $feuille->setCellValueByColumnAndRow(2, 1, 'nd');
    $feuille->setCellValueByColumnAndRow(3, 1, 'nb_call');
    $feuille->setCellValueByColumnAndRow(4, 1, 'date_response');
    $feuille->setCellValueByColumnAndRow(5, 1, 'gestco');
    $feuille->setCellValueByColumnAndRow(6, 1, 'montant_gestco');
    $feuille->setCellValueByColumnAndRow(7, 1, 'status');
    $feuille->setCellValueByColumnAndRow(8, 1, 'incident');
    $feuille->setCellValueByColumnAndRow(9, 1, 'operation');
    $feuille->setCellValueByColumnAndRow(10, 1, 'unité');
    for($i;$i< count($data);$i++){
        $feuille->setCellValueByColumnAndRow(0, $i+2, $data[$i]['fullname']);
        $feuille->setCellValueByColumnAndRow(1, $i+2, $data[$i]['phone']);
        $feuille->setCellValueByColumnAndRow(2, $i+2, $data[$i]['nd']);
        $feuille->setCellValueByColumnAndRow(3, $i+2, $data[$i]['nb_call']);
        $feuille->setCellValueByColumnAndRow(4, $i+2, $data[$i]['date_response']);
        $feuille->setCellValueByColumnAndRow(5, $i+2, $data[$i]['gestco']);
        $feuille->setCellValueByColumnAndRow(6, $i+2, $data[$i]['montant_gestco']);
        $feuille->setCellValueByColumnAndRow(7, $i+2, $data[$i]['status']);
        $feuille->setCellValueByColumnAndRow(8, $i+2, $data[$i]['incident']);
        $feuille->setCellValueByColumnAndRow(9, $i+2, $data[$i]['operation']);
        $feuille->setCellValueByColumnAndRow(10, $i+2, $data[$i]['unité']);
    }

    // envoi du fichier au navigateur

    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 

    header('Content-Disposition: attachment;filename="export_Satiscope_'.date('d-m-Y').'.xlsx"'); 

    header('Cache-Control: max-age=0'); 

    $writer = \PHPExcel_IOFactory::createWriter($classeur, 'Excel2007'); 

    $writer->save('php://output');
    }

En complément j'essaye d'extraire environs 4000 enregistrement de ma base. Sur un échantillonage de 1 à environs 1000 cela fonctionne trés bien.

Si quelqu'un a déjà rencontré ce genre de problème, je vous remercie d'avance de votre aide.

4 réponses


verifie que tes conf php soient identiques. tu as surement moins de mémoire alloué en prod que sur ta dev.
Vérifie aussi que tu as les memes modules d'installé entre ta prod et ta dev

C'est bien ce que je pensais cependant je n'ai pas la main sur les confs de mon serveur, n'y aurait-il pas un moyen d'optimisation pour gagné du temps ou de la mémoire ?

je suis pas sur de moi, mais il me semble que $writer->save('php://output'); c'est ca ton problème, tu doit dépasser le max_buffer de ton php de prod.

essaye de faire de la vrai ecriture du fichier

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save(str_replace('.php', '.xlsx', FILE));

a voir ici :

https://phpexcel.codeplex.com/wikipage?title=Examples&referringTitle=Home

et rajoute un error_reporting(0) en haut de ton fichier un fois que tout sera bon, scar si tu as une erreur, les headers n'enverrons pas ton fichier car du texte sera déjà présent avant.