php - Cut off file_get_contents if it takes too long -
i use freegeoip service track visiting website own database. takes while retrieve data. there anyway can cut off retrieval of data if taking long?
here code:
$geoip = @file_get_contents("http://freegeoip.net/csv/{$_server['remote_addr']}");
`
you can create context sent timeout (reference: file_get_contents)
excerpt:
$opts = array('http' => array( 'method' => 'post', 'header' => "content-type: text/xml\r\n". "authorization: basic ".base64_encode("$https_user:$https_password")."\r\n", 'content' => $body, 'timeout' => 60 ) ); $context = stream_context_create($opts); $url = 'https://'.$https_server; $result = file_get_contents($url, false, $context, -1, 40000);
in case should translate (untested):
$opts = array('http' => array( 'method' => 'get', 'header' => "content-type: text/csv", 'content' => '', 'timeout' => 10 ) ); $context = stream_context_create($opts); $url = "http://freegeoip.net/csv/{$_server['remote_addr']}"; $geoip = file_get_contents($url, false, $context, -1, 40000);
Comments
Post a Comment