getResults has a foreach() within it, this is what takes the longest. I want to know how far this iteration is, it doesnt matter to me where the data is stored, but I dont think I should be writing a SQL statement in every iteration to show an update of status.
I’ve never actually used it before, but why don’t you look into something like Gearman? http://gearman.org/
I think you’re able to report on the progress of a task and stuff like that, and as far as I’m aware you could trigger this off via an ajax call and update when the task is finished. As I say I’ve not used Gearman myself, but I think it may do what you need?
"Gets the status for a background job given a job handle. The status information will specify whether the job is known, whether the job is currently running, and the percentage completion. "
An SQL query on every iteration might slow down too much but why not execute it, say, every 5 seconds? Would that be accurate enough for you? Some untested code sample, it shouldn’t be slow:
$start = time();
foreach ($data as $item) {
if (time() - $start >= 5) {
$start = time();
// update status (SQL, file, etc.)
// ...
}
// do your stuff...
}
Or, update status every 1000th iteration:
// suppose that $data is numerically indexed
foreach ($data as $i => $item) {
if ($i % 1000 == 0) {
// update status (SQL, file, etc.)
// ...
}
// do your stuff...
}