<?php |
/** |
* to do 使用file_get_contents,以及stream_context_create获取远程接口,并增加重试 |
* param string $tongjiUrl |
* return string |
*/ |
public function getTongjiUrl( $tongjiUrl ) { |
$optTongji = array ( |
'http' => array ( |
'method' => "GET" , |
'timeout' => 60, |
) |
); |
$context = stream_context_create( $optTongji ); |
$i = 0; |
while ( $i ++ < 5) { |
$tongjiRet = file_get_contents ( $tongjiUrl ,false, $context ); |
if ( empty ( $tongjiRet )) { |
CLogger::notice( "get url return false for $i time!" ); |
usleep(2000); |
continue ; |
} |
return $tongjiRet ; |
} |
} |