Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Dynamic Servers

Laravel Dynamic Servers Laravel Package

spatie/laravel-dynamic-servers

Dynamically spin up and destroy servers from Laravel to handle variable queue workloads. Uses provider snapshots as templates and lets you determine server count (e.g., based on Horizon wait times) so extra workers are created automatically and removed when no longer needed.

View on GitHub
Deep Wiki
Context7

Dynamically create and destroy servers

Frequently asked questions about Laravel Dynamic Servers
Which Laravel versions does spatie/laravel-dynamic-servers support?
The package supports Laravel 9.x and 10.x. Always check the package’s [Packagist page](https://packagist.org/packages/spatie/laravel-dynamic-servers) for the latest version compatibility before installation. Upgrade paths are typically smooth due to Spatie’s focus on backward compatibility.
How do I configure cloud provider adapters (e.g., AWS EC2, DigitalOcean)?
The package uses a plugin-based architecture for cloud providers. You’ll need to create custom adapters by implementing the `ServerProvider` interface. Spatie’s other packages (like `laravel-aws`) often serve as reference points. Documentation for this is minimal, so start by reviewing the [GitHub issues](https://github.com/spatie/laravel-dynamic-servers/issues) for community implementations.
Can I use this for production workloads like CI/CD pipelines or batch jobs?
Yes, but with caution. The package is designed for event-driven scaling, making it ideal for CI/CD or batch processing. Ensure you configure proper timeouts (TTL) for servers and integrate with cloud cost monitoring (e.g., AWS Budgets) to avoid unexpected charges. Test failover scenarios rigorously in staging.
How do I trigger server creation/destruction programmatically?
Use the `DynamicServers` facade to define rules via the `determineServerCount` method. Pass a closure that evaluates conditions (e.g., queue length) and returns the desired server count. Example: `DynamicServers::determineServerCount(fn($servers) => $servers->needed(5));`. This runs every minute by default, but you can adjust the interval via configuration.
Does this package work with Laravel Horizon for queue-based scaling?
Absolutely. The package integrates seamlessly with Horizon. You can dynamically scale workers by monitoring queue backlogs (e.g., using Horizon’s `WaitTimeCalculator`) and adjusting server counts via `determineServerCount`. This is a common use case for handling spikes in job volume without over-provisioning static servers.
What happens if a server fails to provision or crashes during runtime?
The package includes retry logic for transient failures, but you should implement additional safeguards. For critical workloads, use Laravel’s queue retries or dead-letter queues to handle failed jobs. Monitor server health via cloud provider APIs (e.g., AWS EC2 status checks) and log events using Laravel’s logging or a dedicated monitoring tool like Prometheus.
How do I handle security credentials for cloud providers (e.g., AWS keys)?
Never hardcode credentials. Use Laravel’s `.env` file or a secrets manager like HashiCorp Vault. For AWS, leverage the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. The package itself doesn’t enforce this, so enforce it via your deployment pipeline or Laravel’s built-in validation.
Can I use this alongside Kubernetes or Terraform for hybrid orchestration?
Yes, but define clear boundaries. Use dynamic servers for short-lived, ephemeral workloads (e.g., batch jobs) while relying on Kubernetes or Terraform for stateful services (e.g., databases, APIs). Avoid overlapping responsibilities—dynamic servers aren’t a replacement for full orchestration tools but can complement them for cost-efficient scaling.
How do I test the package locally without spinning up real servers?
Mock the `ServerProvider` interface in your tests. Use Laravel’s `Mockery` or PHPUnit’s `createMock` to simulate server creation/destruction. Test event listeners (e.g., `ServerCreated`) by dispatching fake events. For integration tests, consider using a local cloud emulator like [LocalStack](https://localstack.cloud/) for AWS services.
What are the cost implications of using dynamic servers in production?
Costs vary by provider, but dynamic servers can reduce expenses for sporadic workloads. Mitigate risks by setting hard limits on concurrent servers (e.g., via `maxServers` in config) and integrating with cloud cost alerts. Monitor usage with tools like AWS Cost Explorer or DigitalOcean’s billing API. Always run a cost analysis for your expected workload patterns.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport