Download the PHP package morozmkhl/scalable-db without Composer

On this page you can find all versions of the php package morozmkhl/scalable-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package scalable-db

ScalableDB

Shard routing layer for Laravel 11 applications. The package resolves a tenant or entity key to a database shard, switches the default connection for the duration of a callback or HTTP request, and provides optional fail-over and operational CLI commands.

Tests

Requirements

Component Version
PHP ^8.2
Laravel ^11.5

Installation

Optional publish targets:

The scalable-db-database tag provides a sample database-shards.php stub with read/write host configuration.

Configuration

Publish config/scalable-db.php and define shard connections in config/database.php. Each shard entry maps a logical name to a Laravel connection name and an optional list of replica connections used during fail-over.

Fail-over is disabled by default. Set auto_failover to true to enable replica retry on PDOException.

Further reference: Configuration.

Sharding strategies

Hash

Assigns keys using crc32((string) $key) % shard_count and a slot-to-shard map.

Range

Assigns keys by inclusive numeric ranges.

Lookup

Resolves keys from a lookup table (for example, tenants). Supports optional query result caching.

Strategy details: Sharding strategies.

Read/write splitting

ScalableDB does not implement read/write routing. Configure read, write, and sticky on each shard connection in config/database.php using Laravel's built-in behaviour. The package switches the default connection to the shard master; Laravel routes individual statements to read or write hosts within that connection.

Optional helpers select the read or write PDO for the current connection:

HTTP middleware

Register routes behind the shard.tenant middleware alias. The middleware resolves a tenant identifier in the following order:

  1. $request->user()->tenant_id, or $request->user()->id when tenant_id is absent
  2. HTTP header X-Tenant-ID
  3. Query parameter tenant_id

If no tenant identifier is present, the request proceeds without changing the active shard.

Artisan commands

Command Description
php artisan shard:migrate [--shard=NAME] [--path=PATH] Run migrations on all shards or one shard
php artisan shard:seed Run the configured seeder class
php artisan shard:status Report connectivity for masters and replicas
php artisan shard:diagnose [--json] Full diagnostics; exit code 1 on failure

Command reference: CLI.

Events

Event Dispatched when
ShardResolved A shard name is resolved from a tenant key
ShardFailover Fail-over switches from master to a replica or fallback connection

Telescope

Laravel Telescope is an optional dependency. When present, the package registers a watcher that tags entries with shard:<name> based on the active shard context.

Testing

The test suite uses Pest and Orchestra Testbench. CI runs lint, static analysis, a PHP 8.2/8.4 × SQLite/MySQL matrix, and a Docker demo smoke test.

Demo environment

A Docker-based demo application is provided under demo/.

See Demo.

Limitations

Documentation

Full documentation is in docs/: installation, configuration, architecture, API, CLI, and development notes.

Contributing

Run the following before opening a pull request:

Code style is enforced with Laravel Pint. Static analysis uses PHPStan with Larastan.

License

The MIT License. See LICENSE.


All versions of scalable-db with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^11.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package morozmkhl/scalable-db contains the following files

Loading the files please wait ...