vendredi 4 janvier 2019

How to stagger loop every 10 minutes

Summary of Issue

I have a command that I run every hour. It loops over and array of 6 items and posts data to twitter. The issue is that it posts all 6 items to twitter at once. I'd like for each element of the loop to be staggered every 10 minutes. This way the twitter followers do not get spammed with tweets from us every hour.

What I've Tried

I did do a not so elegant solution to this. Simply adding sleep(600); to the loop.

foreach ($parks as $park) {
    Twitter::post(...);
    sleep(600);
}

This works fine, but I feel like there is a better way than having this process live for an hour.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Fa6OrK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire