0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHP3でfindしたときメモリ足りなくなった

Posted at

なんも気にせず全件findしてぐるぐる処理しようとしていたら Allowed memory size で落ちた

$query = $this->Table->find();
foreach ($query as $entity) {
    // いろんな処理
    // 何千件か処理したところで突然の死!!
}

1レコードでかいからかなーとか思っていたけどそれも違う。
foreachのなか全てコメントアウトしても一緒…
なんでや!! と思っていたら公式にちゃんと載ってた。
「結果をキャッシュしつつ イテレートします」と…
http://book.cakephp.org/3.0/ja/orm/retrieving-data-and-resultsets.html#id15

クエリーが遅延評価されるとこだけ見て勘違いしていた。
http://book.cakephp.org/3.0/ja/orm/query-builder.html#id6

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?