PHP code example of sakura-internet / saklient

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

    

sakura-internet / saklient example snippets




 \Saklient\Cloud\API::authorize(YOUR_API_TOKEN, YOUR_API_SECRET, ZONE);
// ZONE: "is1a" (Ishikari 1st zone), "is1b" (Ishikari 2nd zone), "tk1v" (Sandbox)
// "tk1v" is recommended for tests

// ...



$servers = $api->server->find();

// This doesn't work well
while ($server = array_shift($servers)) {
    //...
    
    // The same goes for accessors
    while ($tag = array_shift($server->tags)) {
        //...
    }
}

// This works well
$servers_array = (array)$servers;
while ($server = array_shift($servers_array)) {
    //...
    
    $tags_array = (array)$server->tags;
    while ($tag = array_shift($tags_array)) {
        //...
    }
}

// This works well because ArrayObject implements IteratorAggregate
foreach ($servers as $server) {
    //...
    
    foreach ($server->tags as $tag) {
        //...
    }
}

// This works well too because ArrayObject implements ArrayAccess and Countable
for ($i=0; $i < count($servers); $i++) {
    $server = $servers[$i];
    //...
    
    for ($j=0; $j < count($server->tags); $j++) {
        $tag = $server->tags[$j];
        //...
    }
}