Large Result Not Chunked (ARCH7062)
Key php.orm.large-result-not-chunked · Severity info · Category orm
Loading an entire large result set into memory then iterating risks holding millions of rows at once when a streaming/chunk API (chunk, cursor) exists. Chunked processing keeps memory bounded.
Incorrect
Section titled “Incorrect”<?phpforeach (User::all() as $user) { // all rows into memory export($user);}Correct
Section titled “Correct”<?phpUser::chunk(1000, function ($users) { // chunk by chunk foreach ($users as $user) { export($user); }});Process large result sets in chunks/streams with chunk/cursor.