Important question! Since the hosting allocated no more than 128MB of RAM, I can not handle large Excel files.

Actually, I need to convert any Excel file to CSV. But with very large amounts of data, the PHP script lacks RAM.

The main rule: memory_limit is installed only in php.ini and there is no other way to install it.

Actually here is the code:

<?php header("Content-Type: text/plain; charset=utf-8"); ini_set("display_errors", "On"); error_reporting(E_ALL); set_time_limit(0); require_once "./class/PHPExcel.php"; $source = $_GET['source']; // large.csv = 42M or large.xlsx = 15M // Установка метода всё равно не снимает использование RAM-машины $method = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; $arguments = ["cacheMemorySize" => "1024M"]; PHPExcel_Settings::setCacheStorageMethod($method, $arguments); $type = PHPExcel_IOFactory::identify($source); $reader = PHPExcel_IOFactory::createReader($type); // Результат после выполнения : $reader->load("large.csv"); // FATAL ERROR: Allowed memory size of 134217728 bytes exhausted (tried to // allocate 32 bytes) in [path_to_class]/PHPExcel/Cell.php on line 550 // // Результат после выполнения : $reader->load("large.xlsx"); // FATAL ERROR: Allowed memory size of 134217728 bytes exhausted (tried to // allocate 218235205 bytes) in /home/max/localhost/html/class/PHPExcel/Reader/Excel2007.php // on line 327 /*$excel = */ $reader->load($source); ?> 

And here is the actual QUESTION (s):

  1. How to install instead of using RAM - the specified folder? (eg ./temp/)

  2. Is it possible to do this?

    3 answers 3

    Try SimpleExcel , it is much less demanding of server resources.

    PHPExcel can also be used in such limited resources, but it is somewhat more complicated. For example, here are some tips on how to read a file in stages, only the necessary columns, etc. which implies less RAM consumption. Use the same folder instead of RAM - definitely not.

      And so it is impossible?

      echo ini_get ("memory_limit"). "\ n"; ini_set ("memory_limit", "256M"); echo ini_get ("memory_limit"). "\ n";

      there is no such thing in PHP as a folder on the server instead of memory

        https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/04-Configuration-Settings.md

         $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_discISAM; $cacheSettings = array( 'dir' => '/temp' ); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); 

        but it still does not help, PHPExcel eats memory in tens of megabytes, even with caching settings in the file! This library is a programmer's nightmare. Try another one: https://github.com/mk-j/PHP_XLSXWriter promise:

        Never run out of memory with PHPExcel again.