> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP SDK configuration

> Timeouts, cURL options and proxies, logging, per-request configuration, and automatic retries in the Telnyx PHP SDK.

## Custom Request Timeouts

To modify request timeouts (connect or total, in seconds) you'll need to tell the API client to use a CurlClient other than its default. You'll set the timeouts in that CurlClient.

```php theme={null}
// set up your tweaked Curl client
$curl = new \Telnyx\HttpClient\CurlClient();
$curl->setTimeout(10); // default is Telnyx\HttpClient\CurlClient::DEFAULT_TIMEOUT
$curl->setConnectTimeout(5); // default is Telnyx\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT

echo $curl->getTimeout(); // 10
echo $curl->getConnectTimeout(); // 5

// tell Telnyx to use the tweaked client
\Telnyx\ApiRequestor::setHttpClient($curl);

// use the Telnyx API client as you normally would
```

## Custom cURL Options (proxies)

Need to set a proxy for your requests? Pass in the requisite `CURLOPT_*` array to the CurlClient constructor, using the same syntax as `curl_stopt_array()`. This will set the default cURL options for each HTTP request made by the SDK, though many more common options (e.g. timeouts; see above on how to set those) will be overridden by the client even if set here.

```php theme={null}
// set up your tweaked Curl client
$curl = new \Telnyx\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
// tell Telnyx to use the tweaked client
\Telnyx\ApiRequestor::setHttpClient($curl);
```

Alternately, a callable can be passed to the CurlClient constructor that returns the above array based on request inputs. See `testDefaultOptions()` in `tests/CurlClientTest.php` for an example of this behavior. Note that the callable is called at the beginning of every API request, before the request is sent.

## Configuring a Logger

The library does minimal logging, but it can be configured
with a \[`PSR-3` compatible logger]\[psr3] so that messages
end up there instead of `error_log`:

```php theme={null}
\Telnyx\Telnyx::setLogger($logger);
```

## Per-request Configuration

For apps that need to use multiple keys during the lifetime of a process it's also possible to set a
per-request key and/or account:

```php theme={null}
\Telnyx\NumberOrder::all([], [
    'api_key' => 'KEY0123...'
]);

\Telnyx\NumberOrder::retrieve("12ade33a-21c0-473b-b055-b3c836e1c292", [
    'api_key' => 'KEY0123...'
]);
```

## Automatic Retries

The library can be configured to automatically retry requests that fail due to
an intermittent network problem:

```php theme={null}
\Telnyx\Telnyx::setMaxNetworkRetries(2);
```
