The Movie Database-ondersteuning

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 antwoorden (op pagina 1 van 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.

Film of tv-serie niet gevonden? Log dan in om deze te creëren.

Wereldwijd

s focus op zoekbalk
p open profielmenu
esc sluit een open venster
? open sneltoetsen venster

Op media pagina's

b ga terug (of ga naar bovenliggend item)
e ga naar beweken

Op TV seizoenspagina's

(rechter pijl) ga naar volgende seizoen
(linker pijl) ga naar vorig seizoen

Op pagina's met TV-programma's

(rechter pijl) ga naar volgende aflevering
(linker pijl) ga naar vorige aflevering

Op alle afbeeldingspagina's

a open venster afbeelding toevoegen

Op alle bewerkte pagina's

t open vertaalmenu
ctrl+ s verstuur formulier

Op discussiepagina's

n start nieuwe discussie
w Verander kijk status
p privé of openbaar
c gesloten of open
a open activiteit
r beantwoord discussie
l ga naar laatste antwoord
ctrl+ enter verstuur uw bericht
(rechter pijl) volgende pagina
(linker pijl) vorige pagina

Instellingen

Want to rate or add this item to a list?

Inloggen