I don't know if I am doing something incorrect or if Twilio is just naturally slow at requesting records. When requesting a list of conferences with php the response can take up to 5-7 minutes which doesn't seem viable for any type of application.
Here is a sample of the code I am using:
$conferences = $client->account->conferences->getIterator(0, 50, array(
));
foreach ($conferences as $conference) {
$conferenceRoom = $client->account->conferences->get($conference->sid);
$date1 = new DateTime($conference->date_created);
$date2 = new DateTime($conference->date_updated);
$interval = $date1->diff($date2);
$page = $conferenceRoom->participants->getPage(0, 50);
$participants = $page->participants;
$participantCount = count($participants);
$result['conferences'][$conference->sid]['friendly_name'] = $conference->friendly_name;
$result['conferences'][$conference->sid]['sid'] = $conference->sid;
$result['conferences'][$conference->sid]['participants'] = $participantCount;
$result['conferences'][$conference->sid]['status'] = $conference->status;
$result['conferences'][$conference->sid]['duration'] = $interval->format('%H:%I:%S%');
$result['conferences'][$conference->sid]['date_created'] = strtotime($conference->date_created);
$result['conferences'][$conference->sid]['date'] = $conference->date_created;
}
echo json_encode($result);
Twilio developer evangelist here.
You're using the getIterator
method for the conferences resource in the PHP library. getIterator
returns an interator that handles pagination for you, so as long as you continue looping through it, it will keep requesting pages from the Twilio API. My guess is that you have had a lot of conferences so you keep paging for a while.
Also, for each conference you then make an API call for the conference resource and another API call for the participants in the call. Even if you only have 10 conferences in your account, you will be making 30 API calls.
So, whilst Twilio is not taking 5-7 minutes to return one response, your script is doing an awful lot of work with the API that is taking a long time.
I agree with Half Crazed's (great name by the way) suggestion of caching results. You could update a conference object in your own system by setting up an event callback URL for your calls so that Twilio can send you status updates about the conference call and you can save the details about it at that point.