Skip to content

Instantly share code, notes, and snippets.

@MarceloBonifazio
Last active May 26, 2017 22:46
Show Gist options
  • Save MarceloBonifazio/733702fc87d9997a443cc11bcaf21693 to your computer and use it in GitHub Desktop.
Save MarceloBonifazio/733702fc87d9997a443cc11bcaf21693 to your computer and use it in GitHub Desktop.
Teste com limite para que função que faz uma requisição em um serviço terceiro traga um retorno valido
<?php
$controle = 1;
for($i = 1; $i <= 100; $i++){
$retorno = requisicao($i);
echo "<div style='background-color:".($retorno == null ? ( $controle == 3 ? "blue; opacity: .6;'>fatal error no retorno $i" : "red; opacity: .6;'>erro no retorno $i" ) : "green; opacity: .6;'>retorno ".$retorno." valido" )."</div><hr/>";
if ($retorno != null || $controle == 3){
$controle = 1;
}else{
$i--;
$controle++;
}
}
function requisicao($i){
// Retorno randomico
return ( rand(0,1) ? $i : null );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment