DigitalOceanPHP / Client

DigitalOcean API v2 client for PHP
MIT License
709 stars 205 forks source link

Added setTimeout function #156

Closed ghost closed 7 years ago

ghost commented 7 years ago

Ability to set timeout

GrahamCampbell commented 7 years ago

I don't think it makes sense to add this, since it's not part of the interface.

GrahamCampbell commented 7 years ago

This timeout should instead be set at construction imo.

ggedde commented 5 years ago

Not sure why this was closed and not added. It is part of the client and @m0byd1ck PR is easy to implement and would have saved me lots of time.

However, for those looking for example of what @GrahamCampbell is talking about instead of this:

$adapter = new BuzzAdapter('DIGITAL_OCEAN_API_KEY');
$digitalocean = new DigitalOceanV2($adapter);
$digitalocean_sizes = $digitalocean->size()->getAll();

You would do this:

use Buzz\Browser;
use Buzz\Client\Curl;
use Buzz\Client\FileGetContents;
...
$browser = new Browser(function_exists('curl_exec') ? new Curl() : new FileGetContents());
$browser->getClient()->setTimeout(15);
$adapter = new BuzzAdapter('DIGITAL_OCEAN_API_KEY', $browser);
$digitalocean = new DigitalOceanV2($adapter);
$digitalocean_sizes = $digitalocean->size()->getAll();