Skip to content

Commit bc676f5

Browse files
use CURL for ip geolocation, closes #4
1 parent 16e1174 commit bc676f5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/Countries.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,17 @@ public function inEurope($code) {
349349
* @return string
350350
*/
351351
public function ip($ip) {
352-
$response = file_get_contents('http://ip2c.org/' . $ip);
352+
$url = 'http://ip2c.org/' . $ip;
353353

354-
if(!empty($response)) {
355-
$parts = explode( ';', $response );
354+
$curl_handle = curl_init();
355+
curl_setopt($curl_handle, CURLOPT_URL, $url);
356+
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
357+
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
358+
$response_body = curl_exec($curl_handle);
359+
curl_close($curl_handle);
360+
361+
if(!empty($response_body)) {
362+
$parts = explode( ';', $response_body );
356363
return $parts[1] === 'ZZ' ? '' : $parts[1];
357364
}
358365

src/Rates/Clients/JsonVat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function fetch() {
2222

2323
$curl_handle = curl_init();
2424
curl_setopt($curl_handle, CURLOPT_URL, $url);
25-
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0);
25+
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
2626
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
2727
$response_body = curl_exec($curl_handle);
2828
curl_close($curl_handle);

tests/CountriesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ public function test_inEurope() {
3333
self::assertTrue( $countries->inEurope( $country ) );
3434
}
3535
}
36+
3637
}

0 commit comments

Comments
 (0)