Dealing with hanging servers | laravel-dynamic-servers | Spatie

 SPATIE

  Laravel Dynamic Servers
==========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-dynamic-servers](https://spatie.be/docs/laravel-dynamic-servers/v1)  Advanced-usage  Dealing with hanging servers

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-dynamic-servers/v1)

- [ Introduction ](https://spatie.be/docs/laravel-dynamic-servers/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-dynamic-servers/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-dynamic-servers/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-dynamic-servers/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-dynamic-servers/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-dynamic-servers/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-dynamic-servers/v1/about-us)

Basic usage
-----------

- [ Getting started ](https://spatie.be/docs/laravel-dynamic-servers/v1/basic-usage/getting-started)
- [ Configuring your first server type ](https://spatie.be/docs/laravel-dynamic-servers/v1/basic-usage/configuring-your-first-server-type)
- [ Ensuring a number of servers ](https://spatie.be/docs/laravel-dynamic-servers/v1/basic-usage/ensuring-a-number-of-servers)
- [ Rebooting servers ](https://spatie.be/docs/laravel-dynamic-servers/v1/basic-usage/rebooting-servers)
- [ Using multiple server types ](https://spatie.be/docs/laravel-dynamic-servers/v1/basic-usage/using-multiple-server-types)
- [ Manually increasing and decreasing servers ](https://spatie.be/docs/laravel-dynamic-servers/v1/basic-usage/manually-increasing-and-decreasing-servers)

Advanced usage
--------------

- [ Creating your own server provider ](https://spatie.be/docs/laravel-dynamic-servers/v1/advanced-usage/creating-your-own-server-provider)
- [ How servers are managed under the hood ](https://spatie.be/docs/laravel-dynamic-servers/v1/advanced-usage/how-servers-are-managed-under-the-hood)
- [ Dealing with erroring servers ](https://spatie.be/docs/laravel-dynamic-servers/v1/advanced-usage/dealing-with-erroring-servers)
- [ Dealing with hanging servers ](https://spatie.be/docs/laravel-dynamic-servers/v1/advanced-usage/dealing-with-hanging-servers)
- [ Fired Events ](https://spatie.be/docs/laravel-dynamic-servers/v1/advanced-usage/fired-events)
- [ Overriding actions and jobs ](https://spatie.be/docs/laravel-dynamic-servers/v1/advanced-usage/overriding-actions)
- [ Setting a server limit ](https://spatie.be/docs/laravel-dynamic-servers/v1/advanced-usage/setting-a-server-limit)

 Dealing with hanging servers
============================

Starting, stopping, and rebooting server is an asynchronous process. The package uses the self-releasing jobs `VerifyServerStarted`, `VerifyServerStopped`, `VerifyServerDeleted` and `VerifyServerReboot` to determine if such an asynchronous process completes correctly (see ["How servers are managed under the hood"](/docs/laravel-dynamic-servers/v1/advanced-usage/how-servers-are-managed-under-the-hood)).

In the config file you can use the `mark_server_as_hanging_after_minutes` key to specify how long we should wait for such processes to complete. By default, we wait for 10 minutes.

When it takes longer than 10 minutes, we'll consider the server as hanging. In the `dynamic_servers` table we'll update the status of the server to `hanging`. We'll consider that this server is not operational, and we'll not count it when determine how many servers we should start, stop or reboot when calling `DynamicServers::ensure($number)`.

We will also fire an event `ServerHangingEvent` so you can take an appropriate action (sending a notification, manually deleting the server, ...). This event has two properties:

- `$server`: the server that is hanging
- `$previousStatus`: this can be `starting`, `stopping` or `rebooting`.
