Download the PHP package boudhraadhia7/vultr-php-sdk without Composer
On this page you can find all versions of the php package boudhraadhia7/vultr-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download boudhraadhia7/vultr-php-sdk
More information about boudhraadhia7/vultr-php-sdk
Files in boudhraadhia7/vultr-php-sdk
Package vultr-php-sdk
Short Description A modern, typed PHP client for the Vultr API v2 with retries, cursor pagination and PSR-18 support.
License MIT
Homepage https://github.com/BoudhraaDhia7/vultr-php-sdk
Informations about the package vultr-php-sdk
Vultr PHP SDK
A typed PHP client for the Vultr API v2.
It covers instances, DNS, firewalls, block and object storage, snapshots, backups, SSH keys, startup scripts, reserved IPs, ISOs, users, and the read-only catalogues (regions, plans, operating systems, applications). Cursor pagination, retries and error handling are built in.
- No required dependencies. PHP 8.2+,
ext-curlandext-json. - Typed errors. Every failure is an exception, never a magic array.
- Stateless. No hidden "current instance"; a single client is safe to share.
- Injectable transport. Use the bundled cURL client, or route requests
through Guzzle,
symfony/http-clientor anything else that speaks PSR-18. - Tested. 124 unit tests, PHPStan level 8, PHP-CS-Fixer, CI on PHP 8.2-8.4.
Installation
Quick start
Create an API key in the Vultr customer portal under Account > API, and add the IP addresses that will use it to the key's access control list.
Resources
Each resource group hangs off the client:
| Accessor | Covers |
|---|---|
$vultr->account() |
Account details, balance, bandwidth |
$vultr->instances() |
Instances: lifecycle, addresses, backups, ISO, VPC |
$vultr->regions() |
Regions and per-region plan availability |
$vultr->plans() |
Cloud compute and bare metal plans |
$vultr->operatingSystems() |
Deployable OS images |
$vultr->applications() |
One-click and Marketplace applications |
$vultr->snapshots() |
Snapshots, including import from a URL |
$vultr->backups() |
Automatic backups (read-only) |
$vultr->sshKeys() |
SSH public keys |
$vultr->startupScripts() |
Boot and PXE scripts |
$vultr->reservedIps() |
Reserved (floating) IPs |
$vultr->isos() |
Custom and public ISO images |
$vultr->blockStorage() |
Block storage volumes |
$vultr->domains() |
Managed DNS: zones, records, SOA, DNSSEC |
$vultr->objectStorage() |
S3-compatible object storage |
$vultr->firewalls() |
Firewall groups and rules |
$vultr->users() |
Sub-account users and ACLs |
Creating an instance
InstanceBuilder validates the payload before a request leaves your process,
so a missing plan or two conflicting deployment sources fail immediately rather
than as a 400 from the API.
Every builder method returns a new builder, so a partially configured one works as a reusable template:
Deploy from a snapshot, ISO, one-click app or Marketplace image with
fromSnapshot(), fromIso(), fromApplication() or fromMarketplaceApp().
Choosing a second source replaces the first rather than sending both.
Anything the builder does not model goes through set():
Managing instances
Instance ids are always passed explicitly:
Backup schedules are enum-typed, and the fields a cadence requires are checked before the request is sent:
Pagination
Every collection endpoint offers two shapes.
list() returns one Page, which is countable, iterable and carries the
cursors, for when you are paging in a UI:
all() returns a generator that walks every page for you, fetching lazily:
Error handling
Failures throw. There is nothing to check on the return value.
The hierarchy:
Every ApiException carries statusCode(), errorBody(), request() and
response(). The Authorization header on request() is already redacted, so
the exception is safe to log as-is.
Retries
Rate limits, 5xx responses and transport failures are retried with exponential
backoff and full jitter. A Retry-After header is honoured when present, capped
at the configured maximum delay.
Only idempotent methods (GET, HEAD, PUT, DELETE) are replayed after a
5xx or a transport failure, so a POST that may have already created an
instance is never sent twice. A 429 is replayed for any method, because a
rate-limited request was rejected before it was processed.
Configuration
Config is immutable: every with*() call returns a new instance, so one
configured object can be shared between clients and workers.
| Method | Default | Purpose |
|---|---|---|
Config::create($key, $baseUri) |
https://api.vultr.com/ |
Build from an API key |
Config::fromEnvironment($var) |
VULTR_API_KEY |
Read the key from the environment |
withTimeout(float) |
30.0 |
Seconds for the whole transfer |
withConnectTimeout(float) |
10.0 |
Seconds to establish the connection |
withMaxRetries(int) |
2 |
Retry attempts for retryable failures |
withRetryDelays(float, float) |
0.5, 8.0 |
Backoff base and ceiling, in seconds |
withDefaultHeaders(array) |
[] |
Headers added to every request |
withCaBundle(string) |
system store | Path to a CA bundle file or directory |
TLS
Certificate verification is always on and cannot be disabled. If a machine cannot verify Vultr's certificate, point the client at a valid CA bundle rather than turning verification off:
Framework integration
The client is a plain object with no framework coupling. Register it once as a singleton and type-hint it where you need it.
Laravel — in a service provider:
Symfony — in config/services.yaml:
Using your own HTTP stack
Pass a Psr18HttpClient to share your application's client, middleware and
logging with the SDK. This needs psr/http-client and psr/http-factory,
which are optional dependencies of this package.
To test without the network, implement HttpClientInterface yourself; it has a
single send(Request): Response method.
Endpoints not yet modelled
Vultr ships new endpoints regularly. Call them directly and keep the authentication, retries, error mapping and JSON decoding:
Examples
Runnable scripts live in examples/:
| File | Shows |
|---|---|
01-list-instances.php |
Account summary, lazy pagination, byte formatting |
02-create-instance.php |
Building and deploying an instance, polling until ready |
03-error-handling.php |
The exception hierarchy in practice |
04-dns-and-firewall.php |
DNS records and firewall rules with enum parameters |
05-framework-integration.php |
Laravel, Symfony and PSR-18 wiring |
Upgrading from 1.x
Version 2.0 is a rewrite with a new namespace and a new API surface. See UPGRADE.md for a method-by-method mapping and CHANGELOG.md for the full list of changes, including the correctness bugs 1.x shipped with.
Development
Contributions are welcome; see CONTRIBUTING.md.
Security
Report vulnerabilities privately. See SECURITY.md.
License
MIT. See LICENSE.
This package began as a fork of cp6/Vultr-API-PHP-class by corbpie, and has since been rewritten.
All versions of vultr-php-sdk with dependencies
ext-curl Version *
ext-json Version *