我拥有的记录编号只有15000。内存php被配置为使用128 mb。所以我得到了这个错误。
允许内存大小为134217728字节
有两种方法来处理这个问题。
我感到困惑的是,如果我将允许的内存增加到256,那么当数据数变成30000时,这个错误就会再次出现。
因此,在开发大型应用程序时,我不应该使用()吗?或者,随着更多的数据进入,我应该继续增加内存大小。
什么是最好的方法?
发布于 2015-12-02 11:48:01
尝试使用批处理检索数据:
http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#data-in-batches
// fetch 10 customers at a time
foreach (Customer::find()->batch(10) as $customers) {
// $customers is an array of 10 or fewer Customer objects
}
// fetch 10 customers at a time and iterate them one by one
foreach (Customer::find()->each(10) as $customer) {
// $customer is a Customer object
}
// batch query with eager loading
foreach (Customer::find()->with('orders')->each() as $customer) {
// $customer is a Customer object with the 'orders' relation populated
}发布于 2018-06-22 03:55:03
我也有同样的问题,经过几天的研究,问题是activeRecord的对象与其关系的所有对象都在内存中,使得占用内存越来越多,所以我的解决方案是每次循环设置那个关系对象和那个对象本身的函数,这样在那个对象类模型中添加下面的代码:
class ModelObject{
....
public function unsetModel()
{
foreach($this->getRelatedRecords() as $name => $record)
{
unset($this->{$name});
}
unset($this);
}
....
}然后把这个函数叫做foreach:
foreach($modelObjects as $model)
{
....
$model->unsetModel();
}https://stackoverflow.com/questions/34041285
复制相似问题