get_users() timeout on big userbase — options to divide query?

You are on the right track with the batch idea. You’ll need a combination of parameters in your get_users() call. A combination of the “number” and “offset” parameters should get you what you need. In the example below $count is a reference to the batch that’s currently running.

<?php
// inside a loop where $count is the number of times the loop has run
$args = array(
    'number'       => 1000,
    'offset'       => $count * 1000,
);
get_users($args)
?>

UPDATE: $count would start at 0.

The first time through the loop you’d get a set of 1000 users starting from the first user in the database because 0 * 1000 = 0 (no offset)

The second time through the loop you’d get another set of 1000 users starting from the 1001st user in the database because 1 * 1000 = 1000 (i.e. skip the first 1000 results and retrieve the next set)

Your loop should continue for as long as you have results being returned.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)