Я получаю данные из последних 3 постов на IG-канале нашей компании и дополнительно обрабатываю их для виджета IG на нашем веб-сайте.
Я выполнил некоторое устранение неполадок, и, похоже, проблема в части json_decodeдекодирования необработанных данных.
Это данные JSON, извлеченные из IG API:
{"pagination": {"next_max_id": "2034341501387371123_8393175932", "next_url": "https://api.instagram.com/v1/users/8393175932/media/recent?access_token=8393175932.65497a8.29744121571744afacbe375999b2525f\u0026count=1\u0026max_id=2034341501387371123_8393175932"}, "data": [{"id": "2034341501387371123_8393175932", "user": {"id": "8393175932", "full_name": "Coffea", "profile_picture": "https://scontent.cdninstagram.com/vp/e88d6cdddc5697515447cde6330b03ff/5D76FD6E/t51.2885-19/s150x150/38097055_446825915802974_1995256258839445504_n.jpg?_nc_ht=scontent.cdninstagram.com", "username": "coffea.earth"}, "images": {"thumbnail": {"width": 150, "height": 150, "url": "https://scontent.cdninstagram.com/vp/3b467c8e7913ecca2874fcbb055fd5b9/5D645F5D/t51.2885-15/e35/s150x150/59153051_2234956400103169_2351775859365829130_n.jpg?_nc_ht=scontent.cdninstagram.com"}, "low_resolution": {"width": 320, "height": 320, "url": "https://scontent.cdninstagram.com/vp/f34190b7534acd762f6435e12b3dd610/5D5E5025/t51.2885-15/e35/s320x320/59153051_2234956400103169_2351775859365829130_n.jpg?_nc_ht=scontent.cdninstagram.com"}, "standard_resolution": {"width": 640, "height": 640, "url": "https://scontent.cdninstagram.com/vp/8643e994a3a87ca8d93f25bcedd3ebf3/5D5FC6D8/t51.2885-15/sh0.08/e35/s640x640/59153051_2234956400103169_2351775859365829130_n.jpg?_nc_ht=scontent.cdninstagram.com"}}, "created_time": "1556732426", "caption": {"id": "17866442770374263", "text": "Coffee superpower \ud83d\udc4a\ud83d\udca5\nHundreds of millions of people all around the world drink coffee every day. If even a part of them starts thinking about how their everyday habits impact the environment, the results can be enormous. In Coffea, we believe the magic is hidden behind the tiniest things. Even such a common matter like coffee has the power to change the world and from ordinary people makes superheroes thanks to its superpower. Do not hesitate to ask us about the conditions and the environment where the coffee has grown up and who stands behind it. #coffee #coffea #superpower #superman #superhero #rwanda #coffeeorigin #singleorigin #change #environment #roastedcoffee #greencoffee #coffeeimport #ecology #changetheworld #earth #brno", "created_time": "1556732426", "from": {"id": "8393175932", "full_name": "Coffea", "profile_picture": "https://scontent.cdninstagram.com/vp/e88d6cdddc5697515447cde6330b03ff/5D76FD6E/t51.2885-19/s150x150/38097055_446825915802974_1995256258839445504_n.jpg?_nc_ht=scontent.cdninstagram.com", "username": "coffea.earth"}}, "user_has_liked": false, "likes": {"count": 34}, "tags": ["roastedcoffee", "brno", "coffee", "change", "superman", "ecology", "coffeeorigin", "superpower", "greencoffee", "superhero", "rwanda", "environment", "earth", "coffea", "changetheworld", "coffeeimport", "singleorigin"], "filter": "Normal", "comments": {"count": 1}, "type": "image", "link": "https://www.instagram.com/p/Bw7btEuB3Jz/", "location": null, "attribution": null, "users_in_photo": []}], "meta": {"code": 200}}
А это базовая функция PHP json_decode:
$latestpost_coded = file_get_contents("https://api.instagram.com/...&count=1");
$latestpost_data = json_decode($latestpost_coded);
$latestpost = $latestpost_data->data;
Iподтвердили, что это часть кода, которая делает его медленным.УЖАСНО МЕДЛЕННО, примерно 10 секунд загрузки.Первоначально код загружал 3 последних сообщения, но результаты для 3 результатов такие же медленные, как и для одного.