For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
8.0 KiB

  1. # PHPExcel Developer Documentation
  2. ## Configuration Settings
  3. Once you have included the PHPExcel files in your script, but before instantiating a PHPExcel object or loading a workbook file, there are a number of configuration options that can be set which will affect the subsequent behaviour of the script.
  4. ### Cell Caching
  5. PHPExcel uses an average of about 1k/cell in your worksheets, so large workbooks can quickly use up available memory. Cell caching provides a mechanism that allows PHPExcel to maintain the cell objects in a smaller size of memory, on disk, or in APC, memcache or Wincache, rather than in PHP memory. This allows you to reduce the memory usage for large workbooks, although at a cost of speed to access cell data.
  6. By default, PHPExcel still holds all cell objects in memory, but you can specify alternatives. To enable cell caching, you must call the PHPExcel_Settings::setCacheStorageMethod() method, passing in the caching method that you wish to use.
  7. ```php
  8. $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;
  9. PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
  10. ```
  11. setCacheStorageMethod() will return a boolean true on success, false on failure (for example if trying to cache to APC when APC is not enabled).
  12. A separate cache is maintained for each individual worksheet, and is automatically created when the worksheet is instantiated based on the caching method and settings that you have configured. You cannot change the configuration settings once you have started to read a workbook, or have created your first worksheet.
  13. Currently, the following caching methods are available.
  14. #### PHPExcel_CachedObjectStorageFactory::cache_in_memory
  15. The default. If you don't initialise any caching method, then this is the method that PHPExcel will use. Cell objects are maintained in PHP memory as at present.
  16. #### PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized
  17. Using this caching method, cells are held in PHP memory as an array of serialized objects, which reduces the memory footprint with minimal performance overhead.
  18. #### PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip
  19. Like cache_in_memory_serialized, this method holds cells in PHP memory as an array of serialized objects, but gzipped to reduce the memory usage still further, although access to read or write a cell is slightly slower.
  20. #### PHPExcel_CachedObjectStorageFactory::cache_igbinary
  21. Uses PHPs igbinary extension (if its available) to serialize cell objects in memory. This is normally faster and uses less memory than standard PHP serialization, but isnt available in most hosting environments.
  22. #### PHPExcel_CachedObjectStorageFactory::cache_to_discISAM
  23. When using cache_to_discISAM all cells are held in a temporary disk file, with only an index to their location in that file maintained in PHP memory. This is slower than any of the cache_in_memory methods, but significantly reduces the memory footprint. By default, PHPExcel will use PHP's temp directory for the cache file, but you can specify a different directory when initialising cache_to_discISAM.
  24. ```php
  25. $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_discISAM;
  26. $cacheSettings = array(
  27. 'dir' => '/usr/local/tmp'
  28. );
  29. PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
  30. ```
  31. The temporary disk file is automatically deleted when your script terminates.
  32. #### PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp
  33. Like cache_to_discISAM, when using cache_to_phpTemp all cells are held in the php://temp I/O stream, with only an index to their location maintained in PHP memory. In PHP, the php://memory wrapper stores data in the memory: php://temp behaves similarly, but uses a temporary file for storing the data when a certain memory limit is reached. The default is 1 MB, but you can change this when initialising cache_to_phpTemp.
  34. ```php
  35. $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;
  36. $cacheSettings = array(
  37. 'memoryCacheSize' => '8MB'
  38. );
  39. PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
  40. ```
  41. The php://temp file is automatically deleted when your script terminates.
  42. #### PHPExcel_CachedObjectStorageFactory::cache_to_apc
  43. When using cache_to_apc, cell objects are maintained in APC with only an index maintained in PHP memory to identify that the cell exists. By default, an APC cache timeout of 600 seconds is used, which should be enough for most applications: although it is possible to change this when initialising cache_to_APC.
  44. ```php
  45. $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_APC;
  46. $cacheSettings = array(
  47. 'cacheTime' => 600
  48. );
  49. PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
  50. ```
  51. When your script terminates all entries will be cleared from APC, regardless of the cacheTime value, so it cannot be used for persistent storage using this mechanism.
  52. #### PHPExcel_CachedObjectStorageFactory::cache_to_memcache
  53. When using cache_to_memcache, cell objects are maintained in memcache with only an index maintained in PHP memory to identify that the cell exists.
  54. By default, PHPExcel looks for a memcache server on localhost at port 11211. It also sets a memcache timeout limit of 600 seconds. If you are running memcache on a different server or port, then you can change these defaults when you initialise cache_to_memcache:
  55. ```php
  56. $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_memcache;
  57. $cacheSettings = array(
  58. 'memcacheServer' => 'localhost',
  59. 'memcachePort' => 11211,
  60. 'cacheTime' => 600
  61. );
  62. PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
  63. ```
  64. When your script terminates all entries will be cleared from memcache, regardless of the cacheTime value, so it cannot be used for persistent storage using this mechanism.
  65. #### PHPExcel_CachedObjectStorageFactory::cache_to_wincache
  66. When using cache_to_wincache, cell objects are maintained in Wincache with only an index maintained in PHP memory to identify that the cell exists. By default, a Wincache cache timeout of 600 seconds is used, which should be enough for most applications: although it is possible to change this when initialising cache_to_wincache.
  67. ```php
  68. $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_wincache;
  69. $cacheSettings = array(
  70. 'cacheTime' => 600
  71. );
  72. PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
  73. ```
  74. When your script terminates all entries will be cleared from Wincache, regardless of the cacheTime value, so it cannot be used for persistent storage using this mechanism.
  75. #### PHPExcel_CachedObjectStorageFactory::cache_to_sqlite
  76. Uses an SQLite 2 "in-memory" database for caching cell data. Unlike other caching methods, neither cells nor an index are held in PHP memory - an indexed database table makes it unnecessary to hold any index in PHP memory, which makes this the most memory-efficient of the cell caching methods.
  77. #### PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3;
  78. Uses an SQLite 3 "in-memory" database for caching cell data. Unlike other caching methods, neither cells nor an index are held in PHP memory - an indexed database table makes it unnecessary to hold any index in PHP memory, which makes this the most memory-efficient of the cell caching methods.
  79. ### Language/Locale
  80. Some localisation elements have been included in PHPExcel. You can set a locale by changing the settings. To set the locale to Brazilian Portuguese you would use:
  81. ```php
  82. $locale = 'pt_br';
  83. $validLocale = PHPExcel_Settings::setLocale($locale);
  84. if (!$validLocale) {
  85. echo 'Unable to set locale to ' . $locale . " - reverting to en_us" . PHP_EOL;
  86. }
  87. ```
  88. If Brazilian Portuguese language files aren't available, then Portuguese will be enabled instead: if Portuguese language files aren't available, then the setLocale() method will return an error, and American English (en_us) settings will be used throughout.
  89. More details of the features available once a locale has been set, including a list of the languages and locales currently supported, can be found in the section of this document entitled "Locale Settings for Formulae".