@@ -18,6 +18,7 @@ class IPinfo
1818 const COUNTRIES_FILE_DEFAULT = __DIR__ . '/countries.json ' ;
1919 const REQUEST_TYPE_GET = 'GET ' ;
2020 const STATUS_CODE_QUOTA_EXCEEDED = 429 ;
21+ const REQUEST_TIMEOUT_DEFAULT = 2 ; // seconds
2122
2223 public $ access_token ;
2324 public $ cache ;
@@ -27,7 +28,19 @@ class IPinfo
2728 public function __construct ($ access_token = null , $ settings = [])
2829 {
2930 $ this ->access_token = $ access_token ;
30- $ this ->http_client = new Client (['http_errors ' => false ]);
31+
32+ /*
33+ Support a timeout first-class, then a `guzzle_opts` key that can
34+ override anything.
35+ */
36+ $ guzzle_opts = [
37+ 'http_errors ' => false ,
38+ 'timeout ' => $ settings ['timeout ' ] ?? self ::REQUEST_TIMEOUT_DEFAULT
39+ ];
40+ if (isset ($ settings ['guzzle_opts ' ])) {
41+ $ guzzle_opts = array_merge ($ guzzle_opts , $ settings ['guzzle_opts ' ]);
42+ }
43+ $ this ->http_client = new Client ($ guzzle_opts );
3144
3245 $ countries_file = $ settings ['countries_file ' ] ?? self ::COUNTRIES_FILE_DEFAULT ;
3346 $ this ->countries = $ this ->readCountryNames ($ countries_file );
@@ -50,7 +63,6 @@ public function __construct($access_token = null, $settings = [])
5063 public function getDetails ($ ip_address = null )
5164 {
5265 $ response_details = $ this ->getRequestDetails ((string ) $ ip_address );
53-
5466 return $ this ->formatDetailsObject ($ response_details );
5567 }
5668
0 commit comments