Sprijin Bază de date filme (The Movie Database)

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 răspunsuri (pe pagină 1 din 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.

Nu găsiți un film sau un serial? Autentificați-vă pentru a-l crea.

Global

s focalizați bara de căutare
p deschideți meniul profilului
esc închide o fereastră deschisă
? deschideți fereastra de scurtături de la tastatură

Pe paginile media

b înapoi (sau la pornire atunci când este cazul)
e accesați pagina de editare

Pe paginile sezonului TV

(săgeată dreapta) mergeți la sezonul următor
(săgeată stânga) mergeți la sezonul precedent

Pe paginile episoadelor TV

(săgeată dreapta) mergeți la următorul episod
(săgeată stânga) mergeți la episodul anterior

Pe toate paginile de imagini

a deschideți fereastra pentru adăugarea imaginii

Pe toate paginile de editare

t deschide selectorul de traduceri
ctrl+ s trimiteți formularul

Pe paginile de discuții

n creați o nouă discuție
w comutați stare de vizionare
p comutați public/privat
c comutați închidere/deschidere
a deschide activitatea
r răspuns la discuție
l mergeți la ultimul răspuns
ctrl+ enter trimiteți mesajul
(săgeată dreapta) pagina următoare
(săgeată stânga) pagina anterioară

Setări

Doriți să evaluați sau să adăugați acest element într-o listă?

Autentificare