دعم الموقع

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 ردود (على هذه الصفحة 1 من 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 أرسل رسالتك
(السهم الايمن) الصفحة التالية
(السهم الايسر) الصفحة السابقة

الاعدادات

هل تريد تقييم او اضافة هذا العنصر للقائمة؟

تسجيل الدخول