File tree 3 files changed +12
-4
lines changed 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -349,10 +349,17 @@ public function inEurope($code) {
349
349
* @return string
350
350
*/
351
351
public function ip ($ ip ) {
352
- $ response = file_get_contents ( 'http://ip2c.org/ ' . $ ip) ;
352
+ $ url = 'http://ip2c.org/ ' . $ ip ;
353
353
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 );
356
363
return $ parts [1 ] === 'ZZ ' ? '' : $ parts [1 ];
357
364
}
358
365
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ public function fetch() {
22
22
23
23
$ curl_handle = curl_init ();
24
24
curl_setopt ($ curl_handle , CURLOPT_URL , $ url );
25
- curl_setopt ($ curl_handle , CURLOPT_CONNECTTIMEOUT , 0 );
25
+ curl_setopt ($ curl_handle , CURLOPT_CONNECTTIMEOUT , 10 );
26
26
curl_setopt ($ curl_handle , CURLOPT_RETURNTRANSFER , true );
27
27
$ response_body = curl_exec ($ curl_handle );
28
28
curl_close ($ curl_handle );
Original file line number Diff line number Diff line change @@ -33,4 +33,5 @@ public function test_inEurope() {
33
33
self ::assertTrue ( $ countries ->inEurope ( $ country ) );
34
34
}
35
35
}
36
+
36
37
}
You can’t perform that action at this time.
0 commit comments