Download the PHP package kefyusuf/laravel-shard without Composer

On this page you can find all versions of the php package kefyusuf/laravel-shard. 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 laravel-shard

Laravel Shard

Tests Code Quality Latest Stable Version Total Downloads License PHP Version Require

A modular shard locator for Laravel applications that provides deterministic shard routing for shard-key-aware Eloquent workflows. Redis-backed maps and shard-aware queues are optional modules.

✨ Features

πŸ“‹ Requirements

Optional modules

Module Default Needs Provides
core always on β€” strategies, Shardable, builders, CLI
redis on predis + illuminate/redis persistent key→shard map (RedisShardLocator)
queue off illuminate/queue shard-aware jobs (ShardAwareJob, RestoreShardContext)

With redis disabled the package falls back to ArrayShardLocator (process-local map) and deterministic strategy routing. No Redis server is required.

πŸ“š Documentation

πŸš€ Installation

Install the package via Composer:

The package will automatically register its service provider thanks to Laravel's package auto-discovery.

Publish the configuration file:

Run the migrations:

🐳 Local Development (Docker)

The repository ships with a Docker stack that bundles PHP (with the redis extension via PECL), Composer, and a Redis 7 service so you can run the full test suite without installing anything on the host.

Override the PHP version via PHP_VERSION (e.g. make PHP_VERSION=8.4 test).

βš™οΈ Configuration

After publishing the config file, configure your shards in config/redis_sharding.php:

Important Constraints

Supported Query Patterns

Pattern Behavior
Model::find($id), findMany([...]) Routes by primary key when the shard key is the primary key
where($shardKey, '=', $value) Routes to one shard
whereIn($shardKey, [...]) Routes to one or more shards and merges results when needed
get, first, count, exists, value, pluck Shard-aware when the query is deterministic
paginate, simplePaginate, chunk Shard-aware when the query is deterministic
update, delete, touch, increment, decrement Shard-aware when the query is deterministic
upsert Shard-aware when every row contains a resolvable shard key value

Fail-Fast Query Patterns

These paths now throw ShardingException instead of silently using the default connection.

Locator Fallback Store

If you want shard lookups to survive a Redis outage beyond the current PHP process, configure redis_sharding.locator.fallback_store with a Laravel cache store that is independent from Redis.

Example:

Health / metrics endpoint

Enable a JSON health probe for load balancers and uptime checks (no Redis required):

Status is ok (all shards reachable), degraded (partial), or down (none reachable).

Add ?detail=1 for a full diagnostics payload (latency, distribution balance, modules, issues), or use the console:

Programmatic access:

🎯 Quick Start

The steps below match the package consumer smoke test (examples/smoke.php), which installs this package into a fresh Laravel app on every CI run.

1. Install

2. Enable only the modules you need

With redis disabled the package uses ArrayShardLocator and deterministic strategy routing β€” no Redis server required.

3. Add sharding to your models

Use the Shardable trait and override getShardKeyName() (do not redeclare $shardKey; the trait already defines it):

4. Use shard-aware queries

5. Dispatch shard-aware jobs (queue module)

RestoreShardContext job middleware rebinds the shard connection on the worker before handle() runs.

6. Use middleware for request routing

7. Verify the wiring

πŸ”§ Sharding Strategies

The package supports four different sharding strategies:

1. Modulo Strategy

Simple modulo-based distribution. Use only when the shard list is effectively static.

Pros: Simple, predictable distribution Cons: Adding/removing shards remaps most keys and requires explicit data migration

2. Consistent Hashing Strategy

Uses consistent hashing algorithm for better distribution when shards are added/removed.

Pros: Minimal data movement when scaling, good distribution Cons: A rehash still displaces ~half the keys; resharding is all-or-nothing per run

3. Range-Based Strategy

Distributes data based on key ranges.

Pros: Good for time-series or sequential data Cons: Can create hotspots if data isn't evenly distributed

4. Virtual Bucket Strategy (Recommended for resharding)

A key hashes into a fixed bucket (crc32 % N, default 1024) and a persistent bucket→shard map decides placement. Buckets never move implicitly — you move them explicitly and rebalance carries only that bucket's keys (~1/N of the data per move).

See docs/REBALANCE.md for the full workflow.

πŸŽ›οΈ Artisan Commands

Shard Management

Virtual Bucket Management

Monitoring & Analysis

Health Monitoring

Performance Analysis

JSON Output Quick Reference

All commands that support output formatting only accept --format=table or --format=json.

Common payload conventions:

πŸ“Š Monitoring & Performance

Built-in Monitoring System

The package includes a comprehensive monitoring system that tracks shard health, performance, and distribution:

Advanced Health Monitoring

Caching & Performance Optimization

πŸ”„ Advanced Usage

Cross-Shard Query Builder

The package now includes a powerful cross-shard query builder that allows you to query across all shards seamlessly:

Convenient Cross-Shard Methods

Batch Operations Across Shards

Manual Shard Selection

πŸ›‘οΈ Configuration Validation

The package includes comprehensive configuration validation to prevent common setup issues:

Configuration Features

πŸ§ͺ Comprehensive Testing

The package includes extensive testing coverage:

Test Suites

Test Categories

Unit Tests:

Integration Tests:

Feature Tests:

Testing Your Implementation

πŸ—οΈ Real-World Examples

E-commerce Application

Multi-Tenant SaaS Application

Social Media Platform

πŸ“‹ Best Practices

1. Choosing the Right Shard Key

2. Monitoring and Maintenance

3. Handling Relationships

4. Performance Optimization

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

πŸ”§ Troubleshooting

Common Issues

1. Configuration Validation Errors

2. Redis Connection Issues

3. Shard Distribution Problems

4. Performance Issues

Debug Mode

Performance Tuning

πŸ“š Additional Resources

πŸ†• Changelog

See CHANGELOG.md for the full release history (latest: v5.0.0 β€” virtual bucket sharding, cross-shard transactions, deep-module refactor, read replicas, write fencing, Pulse/Octane/tenancy integrations).

πŸ“ License

This package is open-sourced software licensed under the MIT license.

πŸ™ Acknowledgments


Made for the Laravel community.

For questions, issues, or contributions, please visit our GitHub repository.


All versions of laravel-shard with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
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 kefyusuf/laravel-shard contains the following files

Loading the files please wait ...