ghostcompiler/laravel-hetzner-cloud
Composer 安装命令:
composer require ghostcompiler/laravel-hetzner-cloud
包简介
Production-ready Laravel SDK for the Hetzner Cloud API
README 文档
README
Laravel Hetzner Cloud SDK
A premium, feature-rich PHP SDK and Laravel integration for the Hetzner Cloud API, featuring rate-limit handling, automatic retries, and concurrent batch operations.
Features
- 100% Endpoint Coverage: Complete implementation of all servers, volumes, networks, firewalls, load balancers, IPs, and supporting resources.
- Fail-Safe Retries & Backoff: Robust exponential backoff and rate-limit parsing handling
RateLimit-Resetresponse headers automatically. - Concurrently Pooled Processing: Execute calls asynchronously or concurrently in batches.
- Dynamic Filter Builder: Fluent query-building for filtering, page indexing, and sorting.
- Type-Safe DTOs: Automated data hydration into standard PHP DTO structures.
- Custom Exceptions: Specialized mapping of API status codes.
Installation
Install the package via Composer:
composer require ghostcompiler/laravel-hetzner-cloud
Publish the configuration file:
php artisan vendor:publish --provider="Vendor\HetznerCloud\Providers\HetznerCloudServiceProvider" --tag="config"
Add your Hetzner Cloud API Token to your .env file:
HETZNER_CLOUD_TOKEN=your_api_token_here HETZNER_CLOUD_TIMEOUT=30 HETZNER_CLOUD_RETRIES=3 HETZNER_CLOUD_RETRY_BACKOFF=100 HETZNER_CLOUD_LOGGING_ENABLED=true
Usage Examples
Servers
Listing and Filtering Servers
use Vendor\HetznerCloud\Facades\Hetzner; // List the first 50 servers matching a name, sorted by creation date $servers = Hetzner::servers() ->filter(['name' => 'web-01']) ->sort('created:desc') ->perPage(50) ->page(1) ->get(); foreach ($servers as $server) { echo $server->name . ': ' . $server->status . "\n"; }
Paginated Results
$paginated = Hetzner::servers()->paginate(25, 2); $servers = $paginated->items; // ServerCollection $meta = $paginated->pagination; // PaginationMeta DTO echo "Page: " . $meta->page . " of " . $meta->lastPage;
Creating and Deleting a Server
// Create a new server $response = Hetzner::servers()->create([ 'name' => 'database-prod', 'server_type' => 'cx22', 'image' => 'ubuntu-24.04', 'location' => 'fsn1', ]); $server = $response->server; $action = $response->action; $rootPassword = $response->rootPassword; echo "Provisioned server ID: " . $server->id . "\n"; echo "Initial Root Password: " . $rootPassword . "\n"; // Delete the server $deleteAction = Hetzner::servers()->delete($server->id); if ($deleteAction) { echo "Deletion status: " . $deleteAction->status; }
Triggering Server Actions
// Power off a server $action = Hetzner::servers()->powerOff($serverId); echo "Action status: " . $action->status; // running / success // Attach an ISO Hetzner::servers()->attachIso($serverId, 'ubuntu-24.04-preinstall');
Volumes
// Create a volume $response = Hetzner::volumes()->create([ 'name' => 'data-disk', 'size' => 100, 'location' => 'fsn1' ]); $volume = $response->volume; // Attach volume to a server Hetzner::volumes()->attach($volume->id, $serverId); // Resize volume Hetzner::volumes()->resize($volume->id, 250);
Firewalls
// Apply firewall to a server $action = Hetzner::firewalls()->apply($firewallId, $serverId); // Remove firewall from a server Hetzner::firewalls()->remove($firewallId, $serverId);
Asynchronous Requests
// Return a Guzzle Promise immediately $promise = Hetzner::servers()->async()->all(); // Resolve promise when ready $servers = $promise->wait();
Batch Concurrent Operations
// Execute multiple queries concurrently $results = Hetzner::batch([ fn () => Hetzner::servers()->find(1), fn () => Hetzner::servers()->find(2), fn () => Hetzner::volumes()->find(10), ]); $server1 = $results[0]; $server2 = $results[1]; $volume = $results[2];
Exception Handling
All exceptions inherit from Vendor\HetznerCloud\Exceptions\HetznerException.
use Vendor\HetznerCloud\Exceptions\AuthenticationException; use Vendor\HetznerCloud\Exceptions\ValidationException; use Vendor\HetznerCloud\Exceptions\RateLimitException; use Vendor\HetznerCloud\Exceptions\HetznerException; try { Hetzner::servers()->create(['name' => '']); } catch (AuthenticationException $e) { // 401 Unauthorized } catch (ValidationException $e) { // 422 Unprocessable Entity $errors = $e->getErrors(); // Get field-specific validation errors } catch (RateLimitException $e) { // 429 Rate Limit Exceeded $secondsToWait = $e->getSecondsUntilReset(); } catch (HetznerException $e) { // Base exception handler }
Static Analysis & Linting
Run PHPStan static analysis:
vendor/bin/phpstan analyse
Run Psalm static analysis:
vendor/bin/psalm
Format code with Pint:
vendor/bin/pint
Development Environment
Built using ServBay
- Mac M4 Tested
- macOS Apple Silicon
- Powered by ServBay
ghostcompiler/laravel-hetzner-cloud 适用场景与选型建议
ghostcompiler/laravel-hetzner-cloud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.37k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2026 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ghostcompiler/laravel-hetzner-cloud 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ghostcompiler/laravel-hetzner-cloud 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-11