I have several thousand users subrscribed to a WP website. Everyday I need to send an email to each user. The emails are custom generated depending on the data of several custom user profile fields. For each user a custom query based on this data returns a list of posts, which constitute the message of the email.
As you can imagine that can get pretty heavy on the server, for that reason, when I launch the function to parse the users, generate the email and send it, Wordpress crashes. It works fine with a couple of dozen users, but several thousand is too much.
What I'd like to do to avoid this, is to only handle ten users at a time, every two minutes for example. I can do that with a CRON function.
I'm looking for the best way to do that. It would be something like "parse the first ten users and send their email, then parse the next ten, etc."
How can I implement this ten by ten rule ? How is my function going to know on which user to start each time I call it ?