PHP code example of vultr / vultr-php

1. Go to this page and download the library: Download vultr/vultr-php 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/ */

    

vultr / vultr-php example snippets




declare(strict_types=1);

lient::create('Your Lovely Vultr API Key');



declare(strict_types=1);

Psr7\HttpFactory();
$client = Vultr\VultrPhp\VultrClient::create('Heres my api key', new GuzzleHttp\Client(), $http_factory, $http_factory);



declare(strict_types=1);

lient::create('Your Lovely Vultr API Key');

$options = new Vultr\VultrPhp\Util\ListOptions();
// Or
// $options = null;
/**
 * 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.
 */
while (true)
{
	$instances = [];
	foreach ($client->instances->getInstances(null, $options) as $instance)
	{
		$instances[] = $instance;
	}

	// Exit our loop, we have reached the end. Hooray!
	if ($options->getNextCursor() == '')
	{
		break;
	}
	// Setting the "CurrentCursor" will tell the client which page it should transcode the url to make the request too.
	$options->setCurrentCursor($options->getNextCursor());
}



declare(strict_types=1);

es\Instances\InstanceCreate;

$create = new InstanceCreate('ewr', 'vc2-6c-16gb');

$create->setOsId(6969);

$create = $create->withHostname('my-amazing-hostname');

var_dump($create->getOsId(), $create->getHostname());




declare(strict_types=1);

lient::create('Your Lovely Vultr API Key');

try
{
	$account = $client->account->getAccount();
}
catch (Vultr\VultrPhp\Services\Account\AccountException $e)
{
	exit('Just a little http error no biggy :wink: : '. $e->getMessage().PHP_EOL);
}
catch (Vultr\VultrPhp\VultrException $e)
{
	exit('O crap something really bad happen: '.$e->getMessage().PHP_EOL);
}