PHPackages                             dedenfarhanhub/db-failover - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dedenfarhanhub/db-failover

ActiveLibrary

dedenfarhanhub/db-failover
==========================

Laravel DB Failover + Telegram Notification + Circuit Breaker + Dynamic DB Switching

00PHPCI passing

Since Mar 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dedenfarhanhub/db-failover)[ Packagist](https://packagist.org/packages/dedenfarhanhub/db-failover)[ RSS](/packages/dedenfarhanhub-db-failover/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SultanDB - Laravel DB Failover Package
======================================

[](#sultandb---laravel-db-failover-package)

[![Build](https://github.com/dedenfarhanhub/db-failover/actions/workflows/main.yml/badge.svg)](https://github.com/dedenfarhanhub/db-failover/actions/workflows/main.yml/badge.svg)

Description
-----------

[](#description)

**SultanDB** is a Laravel package that automatically performs failover to a backup database connection when the primary connection is down. This package supports:

- Dynamic Connection Switching
- Circuit Breaker Pattern
- Telegram &amp; Slack Notification
- Auto DB Health Monitoring
- Redis Fallback Cache
- CI/CD Pipeline

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require dedenfarhanhub/db-failover
```

### 2. Publish Configuration

[](#2-publish-configuration)

```
php artisan vendor:publish --tag=db-failover-config
```

### 3. Environment Setup

[](#3-environment-setup)

Add the following lines to your `.env` file:

```
DB_FAILOVER_TELEGRAM=true
TELEGRAM_BOT_TOKEN=xxxxxx
TELEGRAM_CHAT_ID=xxxxx
```

Usage Example
-------------

[](#usage-example)

### Middleware Implementation

[](#middleware-implementation)

Add middleware to `app/Http/Kernel.php`:

```
protected $middleware = [
    \SultanDB\Middleware\DBMonitor::class,
];
```

### Sending Manual Telegram Notification

[](#sending-manual-telegram-notification)

```
use SultanDB\Helpers\Telegram;

Telegram::sendMessage("Database is down!");
```

Features
--------

[](#features)

### 1. Dynamic Connection Switching

[](#1-dynamic-connection-switching)

Automatically switches from the `primary` connection to the `secondary` connection if the primary connection fails.

### 2. Circuit Breaker Pattern

[](#2-circuit-breaker-pattern)

Counts the number of failures within a certain period before automatically breaking the connection.

### 3. Automatic Notifications

[](#3-automatic-notifications)

Sends notifications to Telegram if there is any database connection issue.

### 4. Redis Fallback Cache

[](#4-redis-fallback-cache)

Automatically falls back to Redis Cache if all database connections fail.

Configuration
-------------

[](#configuration)

**config/db-failover.php**

```
return [
    'telegram' => [
        'enabled' => env('DB_FAILOVER_TELEGRAM', true),
        'token' => env('TELEGRAM_BOT_TOKEN'),
        'chat_id' => env('TELEGRAM_CHAT_ID'),
    ],
    'circuit_breaker' => [
        'attempt_limit' => 3,
        'timeout' => 300,
    ],
    'db_switch' => [
        'redis_timeout' => 300,
    ],
];
```

Testing
-------

[](#testing)

```
php artisan test
```

Contributing
------------

[](#contributing)

Pull requests are highly welcome 🔥. Please include tests and documentation where possible.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/bea5a5b572ca74faf6bb406638380ebe5c1ab947fa437e16951c3a5ff607c981?d=identicon)[dedenfarhan](/maintainers/dedenfarhan)

---

Top Contributors

[![dedenfarhanhub](https://avatars.githubusercontent.com/u/106763240?v=4)](https://github.com/dedenfarhanhub "dedenfarhanhub (4 commits)")

### Embed Badge

![Health badge](/badges/dedenfarhanhub-db-failover/health.svg)

```
[![Health](https://phpackages.com/badges/dedenfarhanhub-db-failover/health.svg)](https://phpackages.com/packages/dedenfarhanhub-db-failover)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
