PHP code example of srustamov / gcore-php

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

    

srustamov / gcore-php example snippets


use Gcore\Client;

$gcore = new Client(apiKey: getenv('GCORE_API_KEY'));

$zone = $gcore->dns->zones->get('example.com');
echo $zone->name;

foreach ($gcore->dns->zones->list() as $zone) {
    echo $zone->name, PHP_EOL;
}

$paginator = $gcore->dns->zones->list();

$firstPage = $paginator->page(limit: 20);        // one page
$everything = $paginator->all();                 // materialize all pages
$total = $paginator->count();                    // server-reported total

$gcore->dns->zones->list(orderBy: 'name', id: [1, 2]);
// GET /dns/v2/zones?order_by=name&id=1&id=2

$gcore->dns->rrsets->create('example.com', 'www.example.com', 'A', [
    'ttl' => 300,
    'resource_records' => [
        ['content' => ['1.2.3.4']],
    ],
]);

foreach ($gcore->dns->rrsets->list('example.com') as $rrset) {
    echo $rrset->name, ' ', $rrset->ttl, PHP_EOL;
}

$zone = $gcore->dns->zones->get('example.com');

$zone->name;                      // typed
$zone->raw()['brand_new_field'];  // whatever the API actually returned

use Gcore\Exception\NotFoundException;
use Gcore\Exception\RateLimitException;

try {
    $gcore->dns->zones->get('missing.example');
} catch (NotFoundException $e) {
    echo $e->statusCode;   // 404
    echo $e->rawBody;      // the response body, verbatim
} catch (RateLimitException $e) {
    // already retried per the retry policy before reaching you
}

$gcore = new Client(
    apiKey: '...',
    baseUrl: 'https://api.gcore.com',
    timeout: 30.0,
    maxRetries: 2,
    headers: ['X-Trace' => 'abc'],
);

use Gcore\RequestOptions;

$gcore->dns->zones->get('example.com', new RequestOptions(timeout: 5.0, maxRetries: 0));
bash
composer 
bash
php codegen/bin/generate.php dns       # or cdn, or fastedge
vendor/bin/php-cs-fixer fix
vendor/bin/phpunit