duangang2825
duangang2825
2018-05-23 14:24

循环一个file_get_contents直到在php中获得非空的JSON

  • loops
  • php

I have the following code:

<?php
$json = file_get_contents("https://api.nanopool.org/v1/eth/payments/0x218494b2284a5f165ff30d097d3d7a542ff0023B");
$decode = json_decode($json,true);
foreach($decode['data'] as $val){   
 echo date('Y-m-d',$val['date']).' -- '.$val['amount'].' -- '.$val['txHash'].' -- '.$val['confirmed'];
   echo "<br/>";
 }

The API used (nanopool) being extremely unreliable, I get a non empty json (success) every 2 to 10 calls.

I tried to loop the file_get_contents (do... while) until getting a non empty json without success. What can you recommend to loop until I get an answer?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答