1

I need some advice on debugging the code below please.

I'm feeding in Twitter user ids from $userIDArray. Because of Twitter limitations I have to break the calls up into batches of 100. So, if $userIDarray contains 512 users, I'm making 6 simultaneous calls using curl_multi_exec.

When I look at the return data the first batch of 100 responses is always fine, then after that I'm getting batches of only 0 and 1 results being returned. So, from 512 users I might only get return info for 120.

How do I find out what is happening with these calls please?

function getUserInfo() { global $userIDArray; global $counter; global $userInfoArray; $handleArray = array(); $requiredCalls = ceil($counter / 100); echo "Calls ".$requiredCalls."</br>"; $mh = curl_multi_init(); for($i = 0; $i < $requiredCalls; $i++) { $counterLow = $counter - 100; if($counterLow < 0) { $counterLow = 0; } //Take only 100 items $outputUIDArray = array_slice($userIDArray,$counterLow, $counter); //Implode array to string of user ids $uids = implode(",", $outputUIDArray); //echo "UIDs = ".$uids; $handle=curl_init(); curl_setopt($handle,CURLOPT_URL,'https://api.twitter.com/1/users/lookup.json?user_id='.$uids.'&include_entities=false'); curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); $handleArray[] = $handle; curl_multi_add_handle($mh,$handleArray[$i]); echo "Counter low ".$counterLow." Counter high ".$counter."</br>"; $counter -= 100; } $active = null; //execute the handles do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } for($i = 0; $i < $requiredCalls; $i++) { //Get result $result = curl_multi_getcontent ($handleArray[$i]); //echo( $i . "\n" . $results . "\n"); $json_a=json_decode($result,true); echo count($json_a)."</br>"; //print_r($json_a); for($j = 0; $j < count($json_a); $j++) { $userInfoArray[] = $json_a[$j]; } var_dump(curl_multi_info_read($mh)); echo"</br>"; //close the handles curl_multi_remove_handle($mh, $handleArray[$i]); } curl_multi_close($mh); echo "Results in final array ".count($userInfoArray);} 

1 Answer 1

2

I was misinterpreting how array slice works

$outputUIDArray = array_slice($userIDArray,$counterLow, $counter); 

Should be

$outputUIDArray = array_slice($userIDArray,$counterLow, 100); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.