Reputation: 1385
I have problem with Instagram api using PHP. Instagram API url is following:
https://api.instagram.com/v1/media/popular?client_id=c32bb75ba2b449dc93b5461a84d9003e
Using this: https://github.com/cosenary/Instagram-PHP-API
with following code in my php script:
<?php
$instagram = new Instagram('c32bb75ba2b449dc93b5461a84d9003e');
$response = $instagram->getPopularMedia();
header('Content-Type: application/json');
echo json_encode($response, JSON_PRETTY_PRINT);
script execute sometimes longer then 40sec, sometimes no results.
Same problem is with simple call:
<?php
echo file_get_contents('https://api.instagram.com/v1/media/popular?client_id=c32bb75ba2b449dc93b5461a84d9003e')
With simple jquery AJAX request like this(on same server):
$.ajax({
dataType: "jsonp",
cache: false,
url: "https://api.instagram.com/v1/media/popular?client_id=c32bb75ba2b449dc93b5461a84d9003e",
success: function(data) {
console.log(data);
}
});
result come always very fast.
I try this two ways on different servers and results are same. Also in PHP class I try use file_get_content instead CURL but everything is same.
Please help (with PHP).
Upvotes: 0
Views: 2586
Reputation: 1
add Connection: close to the HTTP header you send. in PHP: header('Connection: close');
Upvotes: 0
Reputation: 2914
This means: the connection from your web server to instagram is probably slow because either your web server is far away or uses a very bad route to it or (the more probable explanation) you (your code) are sitting on a very poor hoster which limits bandwith from scripts within web servers.
You can debug that by trying to get contents of other web services or web sites.
Upvotes: 1