Exemple #1
0
 $tw_user = array('id' => $q1a['id'], 'profile_image_url' => $content->profile_image_url, 'screen_name' => $content->screen_name, 'followers_count' => $content->followers_count, 'friends_count' => $content->friends_count, 'last_updated' => date("Y-m-d H:i:s"));
 $db->store_authed_user($tw_user);
 /*
 API Version 1.1 has really killed the limits here; from 350 per hour to 15 per
 15 minutes. Also Follower and Friend lists are now separately rate limited; code
 adjusted below to set individual throttle rates. Thanks Twitter, real helpful (not).
 
 On the plus side, these limits are now not used up elsewhere in the application
 so you can tweet away while this cron is running.
 
 Rate limit checking on every request is still very slow and most sensible
 users would never need it, hence just setting a throttle value once per account.
 */
 //Work out if to throttle
 $ops_array = array('fw' => 'followers_count', 'fr' => 'friends_count');
 $rate_con = $cron->get_remaining_hits();
 $this_limit = 0;
 foreach ($ops_array as $this_op => $this_op_var) {
     if ((int) $rate_con[$this_op . '_reset'] == 0) {
         //Either bang on the reset or we couldn't get a connection
         $this_limit = TWITTER_API_LIMIT;
     } elseif ($rate_con[$this_op . '_remaining'] >= $rate_con[$this_op . '_limit']) {
         //This should never happen
         $this_limit = $rate_con[$this_op . '_limit'];
     } elseif ((int) $rate_con[$this_op . '_remaining'] < 3) {
         //Really don't want to attempt with so few requests remaining. Sleep until reset
         if ((int) $rate_con[$this_op . '_reset'] > 0) {
             sleep($rate_con[$this_op . '_reset']);
         }
         $this_limit = $rate_con[$this_op . '_limit'];
     } else {