Php 保存Instagram图像时出现504错误网关错误

Php 保存Instagram图像时出现504错误网关错误,php,instagram-api,http-status-code-504,bad-gateway,Php,Instagram Api,Http Status Code 504,Bad Gateway,我正试图通过API和file\u put\u contentsphp方法在本地机器上保存Instagram图像 我尝试了sleep()方法 ini_set('max_execution_time', 400); $access_token = ""; $photo_count = 8; $json_link = "https://api.instagram.com/v1/users/self/media/recent/?"; $json_link .="access_token={$acces

我正试图通过API和
file\u put\u contents
php方法在本地机器上保存Instagram图像

我尝试了
sleep()
方法

ini_set('max_execution_time', 400);

$access_token = "";
$photo_count = 8;
$json_link = "https://api.instagram.com/v1/users/self/media/recent/?";
$json_link .="access_token={$access_token}&count={$photo_count}";

$json = file_get_contents($json_link);

$obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $json), true);
$cnt = 1;

foreach ($obj['data'] as $post){
    $pic_text = $post['caption']['text'];
    $pic_link = $post['link'];
    $pic_like_count = $post['likes']['count'];
    $pic_comment_count=$post['comments']['count'];
    $pic_src=str_replace("http://", "https://", $post['images']['standard_resolution']['url']);
    $pic_created_time=date("F j, Y", $post['caption']['created_time']);
    $pic_created_time=date("F j, Y", strtotime($pic_created_time . " +1 days"));
    $img = $_SERVER['DOCUMENT_ROOT']."/assets/images/insta-images/".$cnt.".jpg";
    file_put_contents($img, file_get_contents($pic_src));
    $cnt++;
}
使用上面的代码,只有4个图像成功保存在我的本地计算机上,但我已将照片计数设置为8,脚本仅运行1分钟

我希望至少保存8张图像