{"id":27953882,"url":"https://github.com/vultr/vultr-php","last_synced_at":"2025-09-09T12:46:03.205Z","repository":{"id":40250240,"uuid":"453557195","full_name":"vultr/vultr-php","owner":"vultr","description":"The Official Vultr API PHP Wrapper","archived":false,"fork":false,"pushed_at":"2024-02-13T23:49:08.000Z","size":3452,"stargazers_count":21,"open_issues_count":2,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-01T02:56:19.819Z","etag":null,"topics":["http-client","php","psr-17","psr-18","psr-7","version2","vultr","vultr-api","vultr-api-wrapper","vultr-php"],"latest_commit_sha":null,"homepage":"https://www.vultr.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vultr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-30T01:01:07.000Z","updated_at":"2024-11-09T10:54:24.000Z","dependencies_parsed_at":"2023-02-18T04:10:13.985Z","dependency_job_id":null,"html_url":"https://github.com/vultr/vultr-php","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vultr%2Fvultr-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vultr%2Fvultr-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vultr%2Fvultr-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vultr%2Fvultr-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vultr","download_url":"https://codeload.github.com/vultr/vultr-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251945120,"owners_count":21669276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-client","php","psr-17","psr-18","psr-7","version2","vultr","vultr-api","vultr-api-wrapper","vultr-php"],"created_at":"2025-05-07T17:15:17.498Z","updated_at":"2025-05-07T17:15:18.100Z","avatar_url":"https://github.com/vultr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://www.vultr.com/dist/img/brand/logo-dark.svg\" width=\"300\"\u003e\n\n# Vultr API PHP Client.\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vultr/vultr-php/main/LICENSE)\n[![Vultr-Php Changelog](https://img.shields.io/badge/-changelog-blue)](https://github.com/vultr/vultr-php/blob/main/CHANGELOG.md)\n[![PHP Version Require](http://poser.pugx.org/vultr/vultr-php/require/php)](https://packagist.org/packages/vultr/vultr-php)\n[![Latest Stable Version](http://poser.pugx.org/vultr/vultr-php/v)](https://packagist.org/packages/vultr/vultr-php)\n[![Latest Unstable Version](http://poser.pugx.org/vultr/vultr-php/v/unstable)](https://packagist.org/packages/vultr/vultr-php)\n[![Total Downloads](http://poser.pugx.org/vultr/vultr-php/downloads)](https://packagist.org/packages/vultr/vultr-php)\n[![PHP Tests](https://github.com/vultr/vultr-php/actions/workflows/php.yml/badge.svg?branch=main)](https://github.com/vultr/vultr-php/actions/workflows/php.yml)\n[![Test Coverage](https://vultr.github.io/vultr-php/code-coverage/badge.svg)](https://vultr.github.io/vultr-php/code-coverage/index.html)\n[![Library Documentation](https://img.shields.io/badge/documentation-blue)](https://vultr.github.io/vultr-php/docs/index.html)\n\n## Getting Started\n\nMust have a PSR7, PSR17, and PSR18 Compatible HTTP Client. \n[View all PSR's](https://www.php-fig.org/psr/)\nThis client will act on those interfaces which allow for dependancy injection. See Usage for more info.\nhttps://packagist.org/providers/psr/http-client-implementation\n\n### Installation\n```sh\ncomposer require vultr/vultr-php\n```\n\n### Usage\n\n#### Initializing the client\nOnce decided on what HTTP client implementation that will be used to initiate the client. If the client implementation you chose is a wider used client, it may be possible to be auto detected. This is because this client uses [PHP-Http/Discovery](https://github.com/php-http/discovery).\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire (__DIR__.'/../vendor/autoload.php');\n\n$client = Vultr\\VultrPhp\\VultrClient::create('Your Lovely Vultr API Key');\n```\nThe above code example would try and initialize the client using the HTTP Discovery method. If you wanna customize your http client, or the Discovery Method does not find it, the VultrClient will allow to pass in the PSR18 client along with a PSR17 HTTP Factory.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire (__DIR__.'/../vendor/autoload.php');\n\n$http_factory = new GuzzleHttp\\Psr7\\HttpFactory();\n$client = Vultr\\VultrPhp\\VultrClient::create('Heres my api key', new GuzzleHttp\\Client(), $http_factory, $http_factory);\n```\n\n#### Using the client\nThis client implements all the service endpoints in the current iteration of the version 2 api of vultr. Which can be found [here](https://www.vultr.com/api).\n\nFor more detailed examples view the [examples](https://github.com/vultr/vultr-php/tree/main/examples) folder.\n\n##### Pagination\nThe client uses a linked list to paginate between your cursors. Each list call returns a ListOptions passed by reference which you can manipulate with each subsequent call and thus the function manipulates it as well. This allows you to choose previous and or next cursor links to navigate.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire(__DIR__.'/../vendor/autoload.php');\n\n$client = Vultr\\VultrPhp\\VultrClient::create('Your Lovely Vultr API Key');\n\n$options = new Vultr\\VultrPhp\\Util\\ListOptions();\n// Or\n// $options = null;\n/**\n * Whether you pass in a null $options or a ListOptions. You can always expect to have ListOptions be passed back out too you when calling the function.\n */\nwhile (true)\n{\n\t$instances = [];\n\tforeach ($client-\u003einstances-\u003egetInstances(null, $options) as $instance)\n\t{\n\t\t$instances[] = $instance;\n\t}\n\n\t// Exit our loop, we have reached the end. Hooray!\n\tif ($options-\u003egetNextCursor() == '')\n\t{\n\t\tbreak;\n\t}\n\t// Setting the \"CurrentCursor\" will tell the client which page it should transcode the url to make the request too.\n\t$options-\u003esetCurrentCursor($options-\u003egetNextCursor());\n}\n\n```\n\n#### ModelOptions Usage\nModelOptions are objects that allow the user to pass in many arguments that don't neccessarily belong to a Model object. These are attributes that are specific to creation and update functions throughout the client library. Usage of these objects are quite simple. The idea was to reduce code complexity but also give the flexibility to deprecate certain methods when/if attributes are removed from responses.\n\nLets take InstanceCreate for example. This object has many properties in it, that are all underscore_cased. These property names are than used to generate a request to the api.\n\nTo keep the uniformity between the camelCased functions in this client library. ModelOptions makes use of php's `__call` magic method. In order to set these protected properties you can use variation of with functions example: withYourLovelyPropName('hello_world') or set functions example: setYourLovelyPropName('hello_world').\n\nThese functions will set your attributes that will be used to generate the request of our underscored_props that will be sent to the api.\n\nWith the addition of with and set type functions. There are also get functions that can be used as well. They follow the same camcelCased layout as the with and set functions.\n\nExample usage of these object functions.\n\n```php\n\ndeclare(strict_types=1);\n\nrequire(__DIR__.'/../vendor/autoload.php');\n\nuse Vultr\\VultrPhp\\Services\\Instances\\InstanceCreate;\n\n$create = new InstanceCreate('ewr', 'vc2-6c-16gb');\n\n$create-\u003esetOsId(6969);\n\n$create = $create-\u003ewithHostname('my-amazing-hostname');\n\nvar_dump($create-\u003egetOsId(), $create-\u003egetHostname());\n\n```\n\n#### Exception Usage\n\nAll exceptions are children of VultrException. \n\nException tree\n\n* VultrException\n\t* VultrClientException\n\t* VultrServiceException\n\t\t* AccountException\n\t\t* ApplicationException\n\t\t* BackupException\n\t\t* BareMetalException\n\t\t* BillingException\n\t\t* BlockStorageException\n\t\t* DNSException\n\t\t* FirewallException\n\t\t* InstanceException\n\t\t* ISOException\n\t\t* KubernetesException\n\t\t* LoadBalancerException\n\t\t* ObjectStorageException\n\t\t* OperatingSystemException\n\t\t* PlanException\n\t\t* RegionException\n\t\t* ReservedIPException\n\t\t* SnapshotException\n\t\t* SSHKeyException\n\t\t* StartupScriptException\n\t\t* UserException\n\t\t* VPCException\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire (__DIR__.'/../vendor/autoload.php');\n\n$client = Vultr\\VultrPhp\\VultrClient::create('Your Lovely Vultr API Key');\n\ntry\n{\n\t$account = $client-\u003eaccount-\u003egetAccount();\n}\ncatch (Vultr\\VultrPhp\\Services\\Account\\AccountException $e)\n{\n\texit('Just a little http error no biggy :wink: : '. $e-\u003egetMessage().PHP_EOL);\n}\ncatch (Vultr\\VultrPhp\\VultrException $e)\n{\n\texit('O crap something really bad happen: '.$e-\u003egetMessage().PHP_EOL);\n}\n```\n\n## Documentation\n\nSee our documentation for [detailed information about API v2](https://www.vultr.com/api).\n\nView our code-coverage for a detailed look https://vultr.github.io/vultr-php/code-coverage/index.html\n\nTo view the specific library documentation please view https://vultr.github.io/vultr-php/docs/index.html\n\n## Versioning\n\nThis project follows [SemVer](https://semver.org/) for versioning. For the versions available, [see the tags on this repository](https://github.com/vultr/vultr-php/tags) or for [stable releases](https://github.com/vultr/vultr-php/releases)\n\n## Contribute\n\nFeel free to send pull requests our way! Please see the [contributing guidelines](CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvultr%2Fvultr-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvultr%2Fvultr-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvultr%2Fvultr-php/lists"}