Skip to content

Commit

Permalink
Merge pull request #43 from DavidePastore/add-parameter-to-configure-…
Browse files Browse the repository at this point in the history
…curl-options

First draft of creating a curlOptions key in settings
  • Loading branch information
DavidePastore authored Feb 3, 2019
2 parents b5c3c0c + 7108608 commit 7abfbfb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3,262 deletions.
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,17 @@ $ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
));
```

#### Timeout of the connection
#### cURL options

The number of seconds to wait while trying to connect when you instantiate the object:
The cURL options to use while trying to connect when you instantiate the object:

```php
$ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
"connectionTimeout" => 100
));
```

#### Timeout of cURL

You can set the maximum number of seconds to allow cURL functions to execute when you instantiate the object:

```php
$ipInfo = new DavidePastore\Ipinfo\Ipinfo(array(
"timeout" => 100
"curlOptions" => array(
CURLOPT_CONNECTTIMEOUT => 1,
CURLOPT_TIMEOUT => 2,
CURLOPT_CAINFO => __DIR__ . "/cacert.pem"
)
));
```

Expand Down
18 changes: 9 additions & 9 deletions src/DavidePastore/Ipinfo/Ipinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ public function __construct($settings = array())
//Merge user settings
$this->settings = array_merge(array(
'token' => '',
'connectionTimeout' => 0,
'timeout' => 0,
'debug' => false,
'curlOptions' => array()
), $settings);
}

Expand Down Expand Up @@ -245,13 +244,14 @@ private function makeCurlRequest($address)
echo 'Request address: '.$address."\n";
}

curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $address,
CURLOPT_CONNECTTIMEOUT => $this->settings['connectionTimeout'],
CURLOPT_TIMEOUT => $this->settings['timeout'],
CURLOPT_CAINFO => __DIR__ . "/cacert.pem"
));
curl_setopt_array($curl,
array_replace($this->settings['curlOptions'],
array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $address
)
)
);

$response = curl_exec($curl);

Expand Down
Loading

0 comments on commit 7abfbfb

Please sign in to comment.