我拥有的记录数量仅为15000.并且配置使用的内存php为128 MB.所以我得到这个错误.
允许的内存大小为134217728字节耗尽
有两种方法可以解决这个问题.
DAO http://www.yiiframework.com/doc/guide/1.1/en/database.dao
增加PHP中允许的内存
我感到困惑的是,如果我将允许的内存增加到256,有一天当数据的数量变为30 000时,这个错误将再次出现.
所以当我开发大规模应用程序时,我不应该使用Yii cactiverecord findAll()吗?或者我应该随着更多数据的增加而不断增加内存大小.
什么是最好的方法?
尝试使用批次检索数据:
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 }