1. Go to this page and download the library: Download boudhraadhia7/vultr-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
boudhraadhia7 / vultr-php-sdk example snippets
use BoudhraaDhia7\Vultr\VultrClient;
$vultr = VultrClient::create('YOUR_API_KEY');
// or, keeping the key out of your source:
$vultr = VultrClient::fromEnvironment(); // reads VULTR_API_KEY
foreach ($vultr->instances()->all() as $instance) {
printf("%s %s %s\n", $instance['id'], $instance['label'], $instance['main_ip']);
}
$page = $vultr->instances()->list(perPage: 50);
foreach ($page as $instance) { /* ... */ }
$page->total(); // total records, as reported by Vultr
$page->hasMore(); // is there another page
$page->nextCursor(); // pass back as $cursor
$next = $vultr->instances()->list(perPage: 50, cursor: $page->nextCursor());
foreach ($vultr->instances()->all(['region' => 'ewr']) as $instance) {
// Pages are requested only as you consume them; break out and the
// remaining pages are never fetched.
}
use BoudhraaDhia7\Vultr\Exception\AuthenticationException;
use BoudhraaDhia7\Vultr\Exception\RateLimitException;
use BoudhraaDhia7\Vultr\Exception\ResourceNotFoundException;
use BoudhraaDhia7\Vultr\Exception\TransportException;
use BoudhraaDhia7\Vultr\Exception\ValidationException;
use BoudhraaDhia7\Vultr\Exception\VultrExceptionInterface;
try {
$instance = $vultr->instances()->get($instanceId);
} catch (ResourceNotFoundException) {
// 404
} catch (ValidationException $e) {
// 400 or 422
print_r($e->errorBody());
} catch (AuthenticationException) {
// 401: key missing, malformed or revoked
} catch (RateLimitException $e) {
// 429 that survived the built-in retries
sleep($e->retryAfter() ?? 60);
} catch (TransportException $e) {
// No HTTP response at all: DNS, TLS, timeout, refused connection
} catch (VultrExceptionInterface $e) {
// Anything else from this library
}
use BoudhraaDhia7\Vultr\Config;
use BoudhraaDhia7\Vultr\VultrClient;
$vultr = new VultrClient(
Config::create($apiKey)
->withMaxRetries(4) // default 2; 0 disables
->withRetryDelays(baseDelay: 1.0, maxDelay: 30.0)
->withTimeout(15.0)
->withConnectTimeout(5.0)
);
use BoudhraaDhia7\Vultr\Config;
use BoudhraaDhia7\Vultr\VultrClient;
public function register(): void
{
$this->app->singleton(
VultrClient::class,
fn () => new VultrClient(Config::create((string) config('services.vultr.key'))),
);
}
use BoudhraaDhia7\Vultr\Http\Psr18HttpClient;
$vultr = new VultrClient(
Config::create($apiKey),
new Psr18HttpClient($guzzle, $requestFactory, $streamFactory),
);
$clusters = $vultr->request('GET', 'v2/kubernetes/clusters', ['per_page' => 25]);
// Or keep the raw response when you need headers or the status code.
$response = $vultr->send('GET', 'v2/account');
$response->statusCode();
$response->rateLimitRemaining();
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.