The Movie Database Support

Hello,

I am trying to program a simple movie listing. For testing purpose, I created an array containing several movie IDs. I wrote a Movie class which takes the ID in the constructor method and I'm fetching the data via the API. In the Movie class I am storing the needed data from the json and return them. When I am looping through the IDs array, I am creating each loop a new movie object and output the title. When I load 5 movies in total, it takes 0.4636882 seconds per movie. Is this speed normal or is there a way to program it faster? I also tried to use a php api (tmdb_v3-PHP-API-), but I get the same results regarding the speed. Below is my code I use to get the JSON. I hope somebody can help me.

Regards, Bob

$call = "https://api.themoviedb.org/3/movie/$id?api_key=$this->_apiKey&language=$lan&append_to_response=trailers";


//  Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$call);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

$json = json_decode($result, true);



return $json;

3 replies (on page 1 of 1)

Jump to last post

Hi bobmarley20,

You're probably hitting more network overhead than anything else. Our internal movie response times are sub 50ms.

For starters I would use keep alive HTTP connections, so you're only creating a single network connection. Second is just network latency… What's your response time to the Virginia region? You can check it (roughly of course) here: http://www.cloudping.info

Hey Travis Bell,

Thank you for your answer, I really appreciate your help. I checked out the response time and it is about 150ms to the Virginia region. What do you mean by hitting more network overhead? I am quite new to API calls, so I'm testing a lot. The search works great, maybe that's because the result of the search-call contains a set of movies and not a single movie. But when I send one call for each movie I want to list , it takes too long and I do not know how to fix this issue. It would be great if you could give me an idea of how to make it faster (if possible).

Best regards, Bob

Hi Bob,

What I mean when I say network overhead, is that you'll have the latency of making the request and the time you and I take to open a HTTP connection. So you're time was around 460ms, 150ms of that is simply the time to get the to server let alone the time needed to handshake and establish the actual HTTP connection. So, if you're making a new HTTP connection every time you're wasting a lot of time creating and closing those connections.

Here's a simple example of what I mean. I just did a test myself, and my first request takes 510ms. Since we support keep alive, we can reuse the HTTP connection and my subsequent requests are in the ~90ms range (my latency is around 60ms so that's the server responding in ~30ms). That's a pretty killer savings, and the only difference is the fact that I reuse an already established and open connection. If you open the developer tools in your browser and load the "timings" section, you can see this yourself.

So thats on the first things I would look at changing.

P.S. I wouldn't use append_to_response=trailers, but rather append_to_response=videos. Trailers was deprecated a while back.

Hope that helps.

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login