In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you php export excel 500 error solutions, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
The solution to the 500 error occurred in the php export excel: use the [PHPExcel_Settings::setCacheStorageMethod ()] method to pass the cache mode as a parameter to the method to set the cache.
This article operating environment: windows10 system, php 7, thinkpad T480 computer.
Presumably many friends have encountered the problem of exporting excel, maybe we usually find it convenient to use the phpexcel class. But you will find that it is not so easy to export a large amount of data, which is often accompanied by some timeout or memory overflow problems. Let's take a look at the solution.
PHPExcel is a very powerful PHP open source class for dealing with Excel, but a big problem is that it takes up too much memory. From 1.7.3, it supports setting the caching mode of cell, but it is recommended to use the current stable version 1.7.6, because previous versions will have bug to varying degrees.
On average, PHPExcel uses the memory of 1k/ cells, so large documents can lead to memory consumption quickly. The cell caching mechanism allows PHPExcel to cache small cell objects in memory in disk or APC,memcache or Wincache, although it takes some time to read data, it can help you reduce memory consumption.
By default, PHPExcel still keeps cell objects in memory, but you can customize them. You can use the PHPExcel_Settings::setCacheStorageMethod () method to set the cache mode by passing the cache mode as an argument to this method.
Php Code:
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;PHPExcel_Settings::setCacheStorageMethod ($cacheMethod)
The setCacheStorageMethod () method returns a Bool variable indicating whether the setting was successful (for example, if you set to use the APC cache when APC is not available, it will return false)
Each worksheet has a separate cache, and when a worksheet is instantiated, it is automatically created based on the cache set or configured. Once you start reading a file or you have created the first worksheet, you can no longer change the way the cache is cached.
Currently, there are several caching methods available:
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_in_memory
By default, if you don't initialize any caching methods, PHPExcel will use in-memory caching.
=
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized
Using this caching method, cells are stored in memory in a serialized manner, which is a high performance way to reduce memory usage.
=
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip
Similar to serialization, this method is serialized, followed by gzip compression and then put into memory, which further reduces memory usage, but is a bit slow to read and write.
=
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_to_discISAM
When using cache_to_discISAM, all cells will be saved in a temporary disk file, only their location in the file will be saved in PHP memory, which will be slower than any other way of caching in memory, but can significantly reduce memory usage. Temporary disk files are automatically deleted at the end of the script.
=
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp
Class similar to cache_to_discISAM, when using cache_to_phpTemp, all cells will still exist in the php://temp I cache_to_discISAM O stream, and only their locations will be saved in PHP memory. PHP's php://memory wrapper keeps the data in memory, and php://temp behaves similarly, but when the size of the stored data exceeds the memory limit, it will be saved in a temporary file. The default size is 1MB, but you can modify it during initialization:
Php Code:
$cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;$cacheSettings = array ('memoryCacheSize' = >' 8MB'); PHPExcel_Settings::setCacheStorageMethod ($cacheMethod, $cacheSettings); the php://temp file is automatically deleted at the end of the script.
=
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_to_apc
When using cach_to_apc, the cell is saved in APC and only the index is kept in memory. The default timeout of APC cache is 600s, which is sufficient for most applications. Of course, you can also modify it during initialization:
Php Code:
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_APC;$cacheSettings = array ('cacheTime' = > 600); PHPExcel_Settings::setCacheStorageMethod ($cacheMethod, $cacheSettings)
When the script ends, all data is purged from the APC (ignoring cache time), and this mechanism cannot be used as a persistent cache.
=
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_to_memcache
When using cache_to_memory, the cell object is saved in memcache and only the index is kept in memory. By default, PHPExcel will look for memcache services on localhost and port 11211 with a timeout of 600s. If you are running memcache services on other servers or ports, you can modify them during initialization:
Php Code:
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_memcache;$cacheSettings = array ('memcacheServer' = >' localhost','memcachePort' = > 11211); PHPExcel_Settings::setCacheStorageMethod ($cacheMethod, $cacheSettings)
In terms of initialization settings, MS does not support polling by multiple memcache servers, which is a pity.
When the script ends, all data is cleared from the memcache (ignoring cache time) and cannot be persisted using this mechanism.
=
Php Code:
PHPExcel_CachedObjectStorageFactory::cache_to_wincache
Using cache_towincache, the cell object is saved in Wincache and only the index is saved in memory. By default, the Wincache expiration time is 600 seconds, which is sufficient for most applications. Of course, you can modify it during initialization:
Php Code:
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_wincache;$cacheSettings = array ('cacheTime' = > 600); PHPExcel_Settings::setCacheStorageMethod ($cacheMethod, $cacheSettings)
PHPExcel is still quite powerful, the biggest problem is the memory occupation, when can PHPExcel produce a lightweight version, do not need so many fancy features, just need to export the most common version of data!
These are all the contents of this article entitled "solution to 500 errors in php Export excel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.