foreach running in a 10 minute interval

Asked

Viewed 185 times

1

I have a foreach that has more than 4 thousand elements...

There’s some way to do this foreach and it loops 500 elements every 2 minutes??

  • 2
  • Coincidence you here @rray. The question is about array :D

  • @Wallacemaxters did not answer pq did not have the array tag and pq think it is duplicate :P

1 answer

1

500 to 500 you want to run each 2 minutos? Use the function array_chunk to share your array 500 to 500. And apply a foreach with a Sleep at each iteration with this subdivision of its 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);
 }
  • 2 * 60 * 60? What is the unit of time used in PHP Sleep??

  • 1

    It’s wrong. I’ll correct, that would be 2 hours.

  • Cool - is that some Apis of this type use seconds and others use milliseconds (ai would be (2 * 60 * 1000) - PHP is half a point off the curve for a lot of things, so I asked.

  • 1

    sleep is in seconds, usleep which is in milliseconds. In this case, are two functions that do the same thing, but with different timing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.