I have a foreach that has more than 4 thousand elements ...
Is there any way to do this foreach and it loop 500 elements every 2 minutes ??
I have a foreach that has more than 4 thousand elements ...
Is there any way to do this foreach and it loop 500 elements every 2 minutes ??
From 500 in 500 you want to run every 2 minutos
? Use the array_chunk
function to divide your array
from 500 to 500. And apply a foreach
with a sleep at each iteration with that subdivision of your array.
Example:
$array = range(1, 4000); // Supomos que esse seja os 4000
foreach (array_chunk($array, 500) as $key => $values) {
foreach ($values as $value) {
}
sleep(2 * 60);
}