This is a use case for eager-loading if there is a relationship between the collection being iterated over and the select query being made.
It is difficult suggest anything further without more information about your specific case.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have a table with 700,000 records init with 20 column length, in part of my project I have a foreach which I should select one record from the table, for 400 iterates and 400 select, it took me 46sec to retrieve the 400 results. which is not good. guys do you have any idea to improve the speed and the time I use.
Please or to participate in this conversation.