Closed dacrhu closed 4 years ago
All just respond with the first page of the servers. You need to change the size of the page (max: 50 servers per page
) like:
$hetznerClient->servers()->all(new \LKDev\HetznerCloud\RequestOpts(50))
or if you want to get from the next page you need to change the page:
$hetznerClient->servers()->all(new \LKDev\HetznerCloud\RequestOpts(50,2))
I guess the best way to achieve to get all servers would be:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$client = new \LKDev\HetznerCloud\HetznerAPIClient("<YOUR_API_TOKEN>");
$servers = [];
for ($i = 1; $i < PHP_INT_MAX; $i++) {
$_s = $client->servers()->all(new \LKDev\HetznerCloud\RequestOpts(50, $i));
$servers = array_merge($servers, $_s);
if(empty($_s)){
break;
}
}
echo "Servers: ". count($servers).PHP_EOL;
But you are correct, the method is not correctly named. i will think about a better solution.
$hetznerClient = new \LKDev\HetznerCloud\HetznerAPIClient($token);
foreach ($hetznerClient->servers()->all(new \LKDev\HetznerCloud\RequestOpts(50)) as $server) {
echo $project . ',' . $server->id . ',' . $server->name . ',' . $server->status . PHP_EOL;
}
25
But your second solution working fine. Thank you!
@dacrhu as of 1.8.2 the first solution should work too. There was a wrong parameter assigned within the request, so the per_page
value did not work. (#29)
Hi,
I have 41 servers in cloud. If I try get informations with $hetznerClient->servers()->all() method then get only 25. Can you help me?
Thank you!