Looping through with API requests REALLY slow
I'm trying to loop through a list of user IDs to check the relationship
status on a user. This (limiting the loop to 20) takes long enough to get
the "fatal PHP couldn't process in 30 secs error". ...and I would LIKE to
do quite a bit more than 20 repetitions.
Is there a way to make "batch" requests? Sending IG a list of ALL user IDs
I want to check in one swoop?
Here's my current snippet:
<?php
$i = 0;
foreach(get_user_meta($user_id, 'followed_users', false) as $followed){
if($i < 20){
//Makes sure it's a real Insta user ID
if(strlen($followed) > 2){
$relationshipInfo = $instagram->getUserRelationship($followed);
$relationship = $relationshipInfo->data->outgoing_status;
if( $relationship == 'none' ){
//BAN THEM
update_user_meta($user_id, 'is_banned', 1);
if(!is_page('banned') && (get_user_meta($user_id,
'is_banned', true) == 1)){
//REDIRECT TO 'BANNED' PAGE
$redirect = get_bloginfo("url").'/banned/';
wp_redirect( $redirect );
exit;
}
} else {
//DON'T BAN
update_user_meta($user_id, 'is_banned', 0);
}
}
}
$i++;
}
?>
MANY thanks for any direction.
James
P.S. I do just want to note: I know I could store a list of all users
$current_user follows and check with foreach and inarray to find out if
$current_user unfollowed anyone (as the list of users $current_user
followed through my site is stored to the database) except I'm having
trouble getting the FULL list of users $current_user follows... so solving
that would also, in effect, solve my dilemma.
Thanks again! =)
No comments:
Post a Comment