loadinglucian/laravel-optimal-sqlite
Composer 安装命令:
composer require loadinglucian/laravel-optimal-sqlite
包简介
Production-oriented SQLite defaults for Laravel migrations and runtime connections.
README 文档
README
- Introduction
- Requirements
- Installation
- What It Does
- How This Differs From Nuno's Package
- Configuration
- Existing Databases
- Testing
- License
Introduction
SQLite is a great fit for many Laravel applications, but its best production settings need to be applied at the right time. Some settings belong to each connection, while others affect the database file itself and must be applied before Laravel creates schema tables.
Laravel Optimal SQLite gives your Laravel application production-oriented SQLite defaults without adding a custom command to remember. When you run Laravel's normal migration commands, the package prepares empty SQLite database files before the migrations table is created. At runtime, it applies sensible SQLite connection defaults to every configured SQLite connection.
This package was inspired by Nuno Maduro's
nunomaduro/laravel-optimize-database.
That package showed how useful a small SQLite optimization layer can be for
Laravel. Laravel Optimal SQLite takes the idea further by handling the lifecycle
issues around page_size, WAL mode, VACUUM, and migrate:fresh.
Requirements
Laravel Optimal SQLite requires a Laravel application using a file-backed SQLite
connection. Runtime connection defaults may be applied to any SQLite connection,
but file-level settings such as page_size and auto_vacuum cannot be applied
to :memory: databases.
Laravel package discovery should be enabled so the service provider can register automatically. If your application disables package discovery, manually register the provider:
Loadinglucian\LaravelOptimalSqlite\OptimalSqliteServiceProvider::class,
After installing the package, run your normal Laravel migrations. The package
optimizes empty SQLite database files during php artisan migrate and preserves
those file settings during php artisan migrate:fresh.
Installation
You may install the package with Composer:
composer require loadinglucian/laravel-optimal-sqlite
Laravel will discover the service provider automatically.
After installation, continue using Laravel's standard migration commands:
php artisan migrate php artisan migrate:fresh
You do not need to run a package-specific optimization command.
What It Does
The package applies two kinds of SQLite settings.
Runtime connection settings are applied to every configured SQLite connection before Laravel opens it:
PRAGMA busy_timeout = 5000
PRAGMA cache_size = -20000
PRAGMA foreign_keys = ON
PRAGMA mmap_size = 2147483648
PRAGMA temp_store = MEMORY
PRAGMA synchronous = NORMAL
PRAGMA journal_mode = WAL
File-level settings are applied automatically before migrations create tables:
PRAGMA journal_mode = DELETE
PRAGMA auto_vacuum = INCREMENTAL
PRAGMA page_size = 32768
VACUUM
PRAGMA journal_mode = WAL
This sequence matters. SQLite can only apply page_size at database creation or
during VACUUM while the database is not in WAL mode. The package temporarily
leaves WAL mode, applies the file settings, vacuums the empty database file, and
then restores WAL mode.
The package also replaces Laravel's SQLite db:wipe behavior for file-backed
SQLite databases. Laravel normally empties the SQLite file during db:wipe,
which resets file-level settings such as page_size. Laravel Optimal SQLite
drops schema objects instead, so repeated migrate:fresh runs keep the
optimized file format intact.
How This Differs From Nuno's Package
Nuno's package provided the useful starting point: codify a production-ready SQLite profile for Laravel. Laravel Optimal SQLite keeps that spirit, but it changes the delivery mechanism.
This package does not publish a migration stub. Laravel creates the migrations
table before running the first migration, so a "first" migration is still too
late for some SQLite file settings unless it performs a careful VACUUM flow.
Instead, this package hooks into Laravel's normal migrate command and applies
file-level settings before the migrations table exists.
This package also avoids an extra Artisan command in your day-to-day workflow.
You continue running php artisan migrate and php artisan migrate:fresh.
Finally, this package tests the observed SQLite values after tuning. The test
suite verifies the real PRAGMA values, including page_size, auto_vacuum,
WAL mode, runtime connection settings, and repeated migrate:fresh behavior.
Configuration
By default, every configured SQLite connection receives the package defaults.
You may override runtime settings directly in your config/database.php
connection array:
'sqlite' => [ 'driver' => 'sqlite', 'database' => database_path('database.sqlite'), 'busy_timeout' => 10000, 'journal_mode' => 'WAL', 'synchronous' => 'NORMAL', 'pragmas' => [ 'cache_size' => -40000, 'mmap_size' => 2147483648, 'temp_store' => 'MEMORY', ], ],
The file-level defaults are intentionally not exposed through environment variables. They affect the database file format and should remain stable across environments.
Existing Databases
The automatic migration flow only optimizes SQLite files that do not yet have user-created tables. Existing populated databases are skipped so the package does not unexpectedly rewrite a production database file.
Before applying file-level changes to an existing SQLite database, take a
backup. Then perform the maintenance explicitly in your own deployment process
or call the SQLiteDatabaseOptimizer service from a controlled script.
Testing
You may run the package test suite with Composer:
composer test
The tests use real temporary SQLite files and assert the actual post-tuning
PRAGMA values.
License
Laravel Optimal SQLite is open-sourced software licensed under the MIT license.
loadinglucian/laravel-optimal-sqlite 适用场景与选型建议
loadinglucian/laravel-optimal-sqlite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「sqlite」 「optimization」 「laravel」 「wal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 loadinglucian/laravel-optimal-sqlite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 loadinglucian/laravel-optimal-sqlite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 loadinglucian/laravel-optimal-sqlite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Store your language lines in the database, yaml or other sources
The tenancy/tenancy database driver for sqlite
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Image optimization widget for Yii2 Framework with auto WebP/AVIF image format generation from PNG/JPG files.
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-28