PHPackages                             mirzaaghazadeh/smart-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. [Database &amp; ORM](/categories/database)
4. /
5. mirzaaghazadeh/smart-failover

ActiveLibrary[Database &amp; ORM](/categories/database)

mirzaaghazadeh/smart-failover
=============================

A comprehensive Laravel package for automatic failover handling across databases, caches, queues, and other services with intelligent routing and minimal code integration.

v1.1.3(7mo ago)1901MITPHPPHP ^8.1CI failing

Since Sep 29Pushed 7mo agoCompare

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

READMEChangelog (4)Dependencies (12)Versions (12)Used By (0)

🚀 Laravel SmartFailover
=======================

[](#-laravel-smartfailover)

**The Ultimate Laravel Package for Bulletproof Service Failover**

*Never let a service failure bring down your application again*

[![PHP Version](https://camo.githubusercontent.com/58b6ce1bb2ae84d142c142f4d80b992ae4436a4117ef42618783a808177f6126/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3737374242342e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://php.net)[![Laravel Version](https://camo.githubusercontent.com/96a472cc78708ec918faf1d35aced31a8ec13a43fbc2cce545017c76fa163fd8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d39253230253743253230313025323025374325323031312d4646324432302e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://laravel.com)[![Total Downloads](https://camo.githubusercontent.com/e579a3f0c47eea4b412afeedc03bb35d076fc24553b3503658ea0627ac05eacb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d69727a61616768617a616465682f736d6172742d6661696c6f7665722e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/mirzaaghazadeh/smart-failover)[![License: MIT](https://camo.githubusercontent.com/9218332452902d9e542a100d0af126fd3174a116456614d2cf093546a13783db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666f722d7468652d6261646765)](https://opensource.org/licenses/MIT)[![Tests](https://camo.githubusercontent.com/5529b4b3523b58bed117d6876e3cd1eaf95964a626220892e4b656d2f40b7297/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d69727a61616768617a616465682f536d6172744661696c6f7665722f74657374732e796d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d7465737473)](https://github.com/mirzaaghazadeh/SmartFailover/actions)

[📖 Documentation](#-table-of-contents) • [🚀 Quick Start](#-quick-start) • [💡 Examples](#-usage-examples) • [🏥 Health Monitoring](#-health-monitoring) • [🤝 Contributing](#-contributing)

---

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [🎯 Why SmartFailover?](#-why-smartfailover)
- [✨ Features](#-features)
- [🚀 Quick Start](#-quick-start)
- [⚙️ Configuration](#%EF%B8%8F-configuration)
- [💡 Usage Examples](#-usage-examples)
- [🏥 Health Monitoring](#-health-monitoring)
- [🔔 Notifications &amp; Alerts](#-notifications--alerts)
- [📊 Dashboard Integration](#-dashboard-integration)
- [🧪 Testing](#-testing)
- [📈 Performance](#-performance)
- [🔒 Security](#-security)
- [🤝 Contributing](#-contributing)
- [📄 License](#-license)

---

🎯 Why SmartFailover?
--------------------

[](#-why-smartfailover)

### The Problem 😰

[](#the-problem-)

 ```
graph TD
    A[Your Laravel App] --> B[Single Database]
    A --> C[Single Cache]
    A --> D[Single Queue]

    B --> E[💥 Database Fails]
    C --> F[💥 Cache Fails]
    D --> G[💥 Queue Fails]

    E --> H[🔴 App Crashes]
    F --> H
    G --> H

    style H fill:#ff6b6b
    style E fill:#ff6b6b
    style F fill:#ff6b6b
    style G fill:#ff6b6b
```

      Loading ### The Solution 🎉

[](#the-solution-)

 ```
graph TD
    A[Your Laravel App] --> B[SmartFailover]

    B --> C[Primary DB]
    B --> D[Backup DB]
    B --> E[Primary Cache]
    B --> F[Backup Cache]
    B --> G[Primary Queue]
    B --> H[Backup Queue]

    C --> I[💥 Fails]
    I --> J[✅ Auto Switch to Backup]

    E --> K[💥 Fails]
    K --> L[✅ Auto Switch to Backup]

    G --> M[💥 Fails]
    M --> N[✅ Auto Switch to Backup]

    J --> O[🟢 App Stays Online]
    L --> O
    N --> O

    style O fill:#51cf66
    style J fill:#51cf66
    style L fill:#51cf66
    style N fill:#51cf66
```

      Loading

**SmartFailover** transforms your single-point-of-failure Laravel application into a resilient, self-healing system that automatically switches to backup services when primary ones fail.

### 🎯 Key Benefits

[](#-key-benefits)

Before SmartFailoverAfter SmartFailover💥 Single database failure = App down✅ Automatic failover to backup database🐌 Manual intervention required🚀 Zero-downtime automatic switching😰 No visibility into service health📊 Real-time health monitoring🔥 Panic when services fail😌 Sleep peacefully with alerts---

✨ Features
----------

[](#-features)

### 🛡️ **Bulletproof Service Protection**

[](#️-bulletproof-service-protection)

ServicePrimaryFallbacksHealth Checks🗄️ **Database**MySQL, PostgreSQLMultiple backups✅ Connection tests🚀 **Cache**Redis, MemcachedArray, File✅ Read/Write tests📬 **Queue**SQS, RedisDatabase, Sync✅ Job dispatch tests📧 **Mail**SMTP, SESMailgun, Log✅ Connection tests💾 **Storage**S3, GCSLocal, FTP✅ File operations### 🎯 **Smart Features**

[](#-smart-features)

🔄 Auto Failover🏥 Health Monitoring🔔 Smart Alerts🎛️ Easy IntegrationInstant switching when services failReal-time service health checksSlack, Telegram, Email notificationsMinimal code changes requiredExponential backoff retry logicPerformance metrics trackingIntelligent alert throttlingFluent API designGraceful degradation supportHTTP health endpointsCustom notification channelsLaravel-native integration

---

🚀 Quick Start
-------------

[](#-quick-start)

### 📦 Installation

[](#-installation)

```
# 1️⃣ Install the package
composer require mirzaaghazadeh/smart-failover

# 2️⃣ Publish configuration
php artisan vendor:publish --provider="Mirzaaghazadeh\SmartFailover\SmartFailoverServiceProvider" --tag="config"

# 3️⃣ Configure your services (optional)
php artisan vendor:publish --provider="Mirzaaghazadeh\SmartFailover\SmartFailoverServiceProvider" --tag="migrations"
```

### ⚡ 30-Second Setup

[](#-30-second-setup)

```
// That's it! Start using SmartFailover immediately:

use Mirzaaghazadeh\SmartFailover\Facades\SmartFailover;

// Wrap your existing code with failover protection
SmartFailover::db('mysql', ['mysql_backup'])
    ->cache('redis', ['memcached'])
    ->execute(function() {
        // Your existing Laravel code works unchanged!
        $user = User::create($userData);
        Cache::put('user_' . $user->id, $user, 3600);
        return $user;
    });
```

### 🎉 **That's it! Your app is now bulletproof!**

[](#-thats-it-your-app-is-now-bulletproof)

---

⚙️ Configuration
----------------

[](#️-configuration)

### 🔧 Basic Configuration

[](#-basic-configuration)

The `config/smart-failover.php` file is your control center:

```
