Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curl dns resolution name issue on servers with ipv6 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,21 @@ if ($answerObject->status == 'success') {
```

All other examples you can see in the "[examples](https://github.com/zadarma/user-api-v1/tree/master/examples)" folder.

### \Zadarma_API\Client call with ip dns resolution preferences
On servers with ipv6 can be an issue the curl dns resolution, you can set the preference on dns resolution
```php
<?php
$params = array(
'id' => 'YOURSIP',
'status' => 'on'
);

$zd = new \Zadarma_API\Client(YOUR_KEY, YOUR_SECRET);
/**
* $zd->setIpv4Preference() //prefer ipv4
* $zd->setIpv6Preference() //prefer ipv6
* $zd->setIpAllPreference() //prefer both ipv4 and ipv6 (default behavior)
*/

```
29 changes: 29 additions & 0 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Client
private $secret;
private $httpCode;
private $limits = array();
private $ipPreferences = CURL_IPRESOLVE_WHATEVER;

/**
* @param $key
Expand Down Expand Up @@ -57,6 +58,7 @@ public function call($method, $params = array(), $requestType = 'get', $format =
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HEADERFUNCTION => array($this, 'parseHeaders'),
CURLOPT_HTTPHEADER => $this->getAuthHeader($method, $params),
CURLOPT_IPRESOLVE => $this->ipPreferences
);

$ch = curl_init();
Expand Down Expand Up @@ -104,6 +106,33 @@ public function getLimits()
return $this->limits;
}

/**
* @return $this
*/
public function setIpv4Preference()
{
$this->ipPreferences = CURL_IPRESOLVE_V4;
return $this;
}

/**
* @return $this
*/
public function setIpv6Preference()
{
$this->ipPreferences = CURL_IPRESOLVE_V6;
return $this;
}

/**
* @return $this
*/
public function setIpAllPreference()
{
$this->ipPreferences = CURL_IPRESOLVE_WHATEVER;
return $this;
}

/**
* @param $signatureString
* @return string
Expand Down