file_get_contents无法打开流:连接超时

时间:2020-05-19 21:49:47

标签: php json api file-get-contents

当使用file_get_contents读取API的响应并解析JSON时,进入无限加载状态并命中505网关时,我遇到了问题。

Here is the code: 
<?php 

try {

  while(true) { 
    $url = 'http://floodcrm.net/api.php?key=MY_API_KEY_GOES_HERE&method=get_invite';

   $jsonData = file_get_contents($url);
   $json = json_decode($jsonData,true);

   echo $json['code'];

   if(@file_get_contents($url))
   {
   break;
   }
   sleep(2);
  }




}catch (Exception $e) {
    echo $e->getMessage();
}

?>

它可以正常工作,但过一会儿该站点将再次消失。 真的希望我能对此有所帮助。

0 个答案:

没有答案