Level 75
Been discussed many times stored procedure outside of PHP directly in my SQL.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I currently have a command that runs nightly, and grabs data from one database, runs some logic, then dumps the cleaned up data into another database. The problem is, the database contains 250,000+ rows and growing. What would be the best approach to running this, without slowing down the app? Once it's done, I only have to check for rows that have changed, so that saves some time, but I'm looking for an optimal approach.
Things you need to do
$limit = 5000;
$loopCount = ($totalRows / $limit) + 1;
for ($i = 1; $i <= $loopCount; $i++) {
// todo: sql query using ( ($i > 1 ?: 0) * $limit) as offset, and limit by $limit
if (!count($queried)) continue;
foreach ($queried as $idx => $val) {
// ...
unset($queried[$idx]);
}
}
Please or to participate in this conversation.