PHPackages                             huy-nguyen/laravel-optimize-init-db-connection - 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. huy-nguyen/laravel-optimize-init-db-connection

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

huy-nguyen/laravel-optimize-init-db-connection
==============================================

A package for optimize Laravel init database connection

v1.0.0(2y ago)112.3k↑153.6%[1 PRs](https://github.com/huynt57/laravel-optimize-init-db-connection/pulls)MITPHPPHP &gt;=7.2

Since Feb 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/huynt57/laravel-optimize-init-db-connection)[ Packagist](https://packagist.org/packages/huy-nguyen/laravel-optimize-init-db-connection)[ Docs](https://github.com/huy-nguyen/laravel-optimize-init-db-connection)[ GitHub Sponsors](https://github.com/huynt57)[ RSS](/packages/huy-nguyen-laravel-optimize-init-db-connection/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

This package for optimize Laravel Init Database Connection
==========================================================

[](#this-package-for-optimize-laravel-init-database-connection)

[![Latest Version on Packagist](https://camo.githubusercontent.com/175aa5a81f7d436d4e4e5c5ca6f1e9816e6674d54b39d2b0db2671ed192ec863/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6875792d6e677579656e2f6c61726176656c2d6f7074696d697a652d696e69742d64622d636f6e6e656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/huy-nguyen/laravel-optimize-init-db-connection)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0cc925c6b7a3f5ceedfa4e01bec9b02a2b79aae9e3d3aca97a10ade39a30b55e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6875796e7435372f6c61726176656c2d6f7074696d697a652d696e69742d64622d636f6e6e656374696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/huynt57/laravel-optimize-init-db-connection/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/be06e3979aa4f600d17902091fe1f2ed05926bcbda33d24f7fc3c8765fc97a8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6875792d6e677579656e2f6c61726176656c2d6f7074696d697a652d696e69742d64622d636f6e6e656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/huy-nguyen/laravel-optimize-init-db-connection)

As mentioned in PR [50044](https://github.com/laravel/framework/pull/50044), this package was implemented for lower Laravel version (PHP &gt;= 7.2, Laravel &gt;= 6)

> "The current code does multiple round-trips to set all the variables we need for our config, both because there are multiple commands to run, but also because it's using prepare, for many of them - each use of prepare and execute causes 3 round trips - one to prepare, one to execute, and one to close statement (on garbage collection of the statement in PHP land). The MySQL SET command supports setting multiple things in a comma separated fashion. Refactoring to do this enables us to just run one SET statement against the server. This can make a real difference in a cloud situation such as AWS Lambda talking to an RDS database where we have to go cross-AZ with low single digit ms latency, instead of sub-ms latency. This also reduces load on the DB (fewer statements to execute), so spinning up a bunch of Lambdas in a burst will be less of a burden."

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

[](#installation)

You can install the package via composer:

```
composer require huy-nguyen/laravel-optimize-init-db-connection
```

You can publish the config file with:

```
php artisan vendor:publish --tag="optimize-init-db-connection-config"
```

This is the contents of the published config file:

```
return [
     'driver' => 'mysql',
];
```

Usage
-----

[](#usage)

As default, this package will change your "mysql" connection. You can setup new database connection by:

Change your configuration (`php config/optimize-init-db-connection.php `)

```
return [
     'driver' => 'optimize-mysql',
];
```

Update your driver connection to `optimize-mysql `:

```
'mysql' => [
            'driver' => 'optimize-mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => false,
            'engine' => null,
            'options' => []
        ],
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [huynt57](https://github.com/huynt57)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

871d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5053581?v=4)[Nguyễn Thế Huy](/maintainers/huynt57)[@huynt57](https://github.com/huynt57)

---

Top Contributors

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

---

Tags

laravelhuynt57laravel-optimize-init-db-connection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/huy-nguyen-laravel-optimize-init-db-connection/health.svg)

```
[![Health](https://phpackages.com/badges/huy-nguyen-laravel-optimize-init-db-connection/health.svg)](https://phpackages.com/packages/huy-nguyen-laravel-optimize-init-db-connection)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M633](/packages/spatie-laravel-medialibrary)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

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