laravel/forge-sdk
Official Laravel Forge SDK for PHP: an expressive client for the Forge API to list and manage servers, sites, and services. Instantiate with an API token, fetch resources, and perform actions like creating servers with provider, region, size, and PHP/database options.
wait=true in createSite) aligns with asynchronous workflows (e.g., CI/CD pipelines, auto-scaling triggers). However, this introduces latency if not optimized (e.g., via webhooks or Forge’s native event system).// Register in AppServiceProvider
$this->app->singleton(Forge::class, fn() => new Forge(config('forge.token')));
// Use in a command
$forge = app(Forge::class);
$forge->createServer([...]);
wait parameter helps, but long-running operations (e.g., backups) may need external monitoring (e.g., Laravel Horizon or a dedicated queue worker).| Risk Area | Mitigation Strategy |
|---|---|
| API Versioning | Monitor Forge’s API deprecations; use SDK’s UPGRADE.md to align with major versions. |
| Rate Limiting | Implement exponential backoff for retries (e.g., via Laravel’s Retryable trait). |
| Token Security | Store Forge API tokens in Laravel Vault or environment variables; avoid hardcoding. |
| Idempotency | Use Forge’s idempotency keys for critical operations (e.g., server creation). |
| Error Handling | Extend SDK exceptions (e.g., TimeoutException) with custom retry logic or alerts. |
| Deprecation | Fork the SDK if Laravel Forge discontinues support; maintain a wrapper layer for future-proofing. |
wait=true) or asynchronous (queue-based) workflows.| Component | Compatibility Notes |
|---|---|
| Laravel | Native support for Service Container, Queues, and Artisan. |
| PHP 8.1+ | SDK requires PHP 8.1+; align with Laravel’s supported versions. |
| Composer | Standard composer require installation; no additional dependencies. |
| Forge API | SDK maps to Forge’s v2 API; verify Forge API docs for unsupported endpoints. |
| Database | No direct DB integration, but SDK manages Forge-managed databases (MySQL/Postgres). |
| Queue Workers | Useful for asynchronous operations (e.g., wait=false + queue processing). |
| Testing | Mock Laravel\Forge\Forge in PHPUnit using Laravel’s mocking helpers or Mockery. |
Phase 1: Proof of Concept (PoC)
php artisan forge:create-server).make:command and make:job for async workflows.Phase 2: Core Workflows
TimeoutException).// In a GitHub Actions workflow
- name: Deploy to Forge
run: php artisan forge:deploy --server=$SERVER_ID --wait
Phase 3: Observability & Scaling
Laravel\Queue\InteractsWithQueue with delays).Phase 4: Custom Extensions
ForgeCustomApiClient).class ForgeCustomApi extends Forge {
public function customEndpoint(array $data) {
return $this->client->post('/custom-endpoint', $data);
}
}
composer require laravel/forge-sdk)..env or Vault).feature() helper to toggle SDK functionality.UPGRADE.md for breaking changes.config('forge.token') with environment variables.$forge = new Forge(config('forge.token'), [
How can I help you explore Laravel packages today?