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 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.

映画やテレビ番組が見つかりませんか?ログインして作成してください。

全般

s 検索バーに移動する
p プロファイルメニューを開く
esc 開いているウィンドウを閉じる
? キーボードショートカットウィンドウを開く

メディアのページ

b 戻る(または該当する場合は親に)
e 編集ページに行く

テレビ番組のシーズンのページ

(右矢印)次のシーズンに行く
(左矢印)前のシーズンに戻る

テレビ番組のエピソードのページ

(右矢印)次のエピソードに進む
(左矢印)前のエピソードに戻る

全ての画像のページ

a 画像追加ウィンドウを開く

全ての編集ページ

t 翻訳選択を開く
ctrl+ s フォームを送信する

ディスカッションのページ

n 新しいディスカッションを作成する
w 監視ステータスを切り替える
p 公開/非公開を切り替える
c 閉じる/開くを切り替える
a アクティビティを開く
r ディスカッションに返信
l 最後の返事に行く
ctrl+ enter メッセージを送信する
(右矢印)次のページ
(左矢印)前のページ

設定

このアイテムを評価したり、リストに追加したりしたいですか?

ログイン

メンバーではありませんか?

登録してコミュニティに参加