Assuming User is a model which extends Doctrine_Record, consider the below (arbitrary) code that creates 5000 user records.
$conn->beginTransaction();
for ($i = 1, $i < 5001, $i++) {
$user = new User();
$user->some_field = $i;
$user->save();
$user->free(true);
}
$conn->commit();
I am finding that this script is timing out after 30 seconds and not managing to create all the Users. Are there ways to optimize this code to work more quickly? I am considering just writing regular old SQL to create the records but then I lose the power of the Doctrine_Record, including insert hooks etc (Note that this script times out even if there are NO hooks in the User model).
Any advice?