【问题标题】:phpExcel how do I pass settings into classphpExcel如何将设置传递给类
【发布时间】:2013-01-16 13:30:19
【问题描述】:

由于内存问题(不断耗尽),我基本上试图启用单元缓存,它是一个相当大的电子表格。从我读过的内容来看,在线单元缓存是一个很好的方法

根据我在网上找到的示例,它看起来像这样

Cell caching and memory leak

stackoverflow - fix memory error

$oExcel = new PHPExcel();
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '512MB');

PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);

上面的问题是我没有用设置设置excel对象吗?

$oExcel->setCacheStorageMethod($cacheMethod,$cacheSettings); // this returns method not found error

我认为我只是初始化错了吗?

【问题讨论】:

  • 所以文档说setCacheStorageMethod 是静态的?
  • 无法在文档中找到对它的引用。然而发现这是讨论。 phpexcel.codeplex.com/discussions/234530
  • Here you can find similar question with quite extensive answer 包括 setCacheStorageMethod 的工作示例。希望对您有所帮助!
  • 对于文档,我的意思是无论您在哪里阅读 PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings); 位。它显示为PHPExcel_Settings 类的静态方法,而不是PHPExcel 类的常规方法。

标签: php caching memory-leaks phpexcel


【解决方案1】:

在开发人员文档的第 4.2.1 节中有描述:标题为“单元缓存”的部分;并且您需要在实例化或加载 PHPExcel 对象之前设置单元缓存

setCacheStorageMethod() 不是 PHPExcel 类的方法,因为您尝试在这一行中使用:

$oExcel->setCacheStorageMethod($cacheMethod,$cacheSettings); 

使用

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '512MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);

$oExcel = new PHPExcel();

并且新的 PHPExcel 对象会自动使用配置的缓存设置(即 phptemp)

【讨论】:

  • 为了使上述工作正常运行,是否必须在运行 setCache 静态方法之后对 new PHPExcel() 进行新的初始化。我有点困惑对象是如何知道新设置的。
  • 是的,之后...... PHPExcel对象构造函数读取您之前定义的缓存设置
猜你喜欢
  • 2014-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-04
  • 2018-08-29
  • 1970-01-01
  • 2020-05-25
  • 1970-01-01
相关资源
最近更新 更多