PHPackages                             sararzbn/queryspy - 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. sararzbn/queryspy

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

sararzbn/queryspy
=================

Laravel profiler for slow queries with smart suggestions

v1.2.1(3w ago)07MITPHP

Since Jun 21Pushed 3w agoCompare

[ Source](https://github.com/sararzbn/queryspy)[ Packagist](https://packagist.org/packages/sararzbn/queryspy)[ RSS](/packages/sararzbn-queryspy/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)DependenciesVersions (7)Used By (0)

🕵️ QuerySpy – Laravel Slow Query Profiler
=========================================

[](#️-queryspy--laravel-slow-query-profiler)

**QuerySpy** is a developer-friendly profiler for Laravel that captures slow SQL queries and suggests optimizations.

🚀 Features
----------

[](#-features)

- Logs all slow database queries
- Clean dashboard with filters and search
- Smart suggestions (e.g. avoid SELECT \*, use WHERE, add LIMIT)
- CLI commands to export or clear query logs
- Works out of the box with zero config
- 100% test coverage

📦 Installation
--------------

[](#-installation)

To install the package, simply run the following Composer command:

```
composer require sararzbn/queryspy

```

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

[](#️-configuration)

Publish the config file to customize QuerySpy:

```
php artisan vendor:publish --tag=queryspy-config

```

This creates `config/queryspy.php` with the following options:

OptionDefaultDescription`enabled``true`Master switch. Set `QUERYSPY_ENABLED=false` in `.env` to disable capturing entirely.`environments``['local', 'staging']`Only capture queries in these environments. An empty array `[]` means capture everywhere.`threshold``300`Queries slower than this many milliseconds are recorded. Override with `QUERYSPY_THRESHOLD`.You can also configure these via `.env`:

```
QUERYSPY_ENABLED=true
QUERYSPY_THRESHOLD=300

```

> **⚠️ Upgrade note (v1.2):** QuerySpy now only captures queries in the environments listed in `environments` (default `local` and `staging`), so it no longer writes to your **production** database out of the box. If you relied on capturing in another environment, add it to the list or set `environments`to `[]`.

🗄️ Database Migration
---------------------

[](#️-database-migration)

QuerySpy stores slow queries in a dedicated database table. To create it, run:

```
php artisan migrate

```

🖥️ Usage
--------

[](#️-usage)

### Dashboard

[](#dashboard)

Open in browser:

```
http://localhost:8000/queryspy

```

### Seeding demo data (for testing)

[](#seeding-demo-data-for-testing)

QuerySpy ships with a seeder that inserts fake slow-query rows into the `query_spy_entries` table, so you can test the dashboard, export, and analyze features without having to generate real slow queries first.

Run it with:

```
php artisan db:seed --class="QuerySpy\Database\Seeders\QuerySpySeeder"

```

This inserts 40 sample slow queries. Use `php artisan queryspy:clear` to wipe them again.

> **Note:** The seeder namespace is registered in the package's `composer.json`autoload. If you change the package's `composer.json`, run `composer update sararzbn/queryspy` so the app picks up the changes.

🛠️ CLI Commands
---------------

[](#️-cli-commands)

Export queries:

```
php artisan queryspy:export --format=csv
php artisan queryspy:export --format=json

```

Clear all recorded slow queries (empties the database table and the log file):

```
php artisan queryspy:clear

```

Analyze recorded slow queries in the terminal (slowest first):

```
php artisan queryspy:analyze

```

Prune old entries so the table doesn't grow forever (uses `retention_days`, default 7):

```
php artisan queryspy:prune
php artisan queryspy:prune --days=30

```

Schedule it in `routes/console.php` (or your scheduler) to run automatically:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('queryspy:prune')->daily();
```

🧩 Roadmap
---------

[](#-roadmap)

- Live dashboard updates (AJAX polling)
- Tag queries with request/user context
- JOIN performance analyzer

👩‍💻 Author
----------

[](#‍-author)

Created with ❤️ by [Sara Rouzbahani](https://github.com/sararzbn)

📄 License
---------

[](#-license)

MIT License

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance94

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.4% 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

Every ~79 days

Recently: every ~99 days

Total

6

Last Release

26d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a8c1df385b899552a31736c218655cabf4693387d200e0dd9bc765571594efd?d=identicon)[root\_rzbn](/maintainers/root_rzbn)

---

Top Contributors

[![sararzbn](https://avatars.githubusercontent.com/u/30994341?v=4)](https://github.com/sararzbn "sararzbn (31 commits)")[![srouzbahani](https://avatars.githubusercontent.com/u/165389961?v=4)](https://github.com/srouzbahani "srouzbahani (24 commits)")

---

Tags

databaselaravellaravel-frameworklaravel-packagen-plus-oneperformanceperformance-analysisqueryslow-query

### Embed Badge

![Health badge](/badges/sararzbn-queryspy/health.svg)

```
[![Health](https://phpackages.com/badges/sararzbn-queryspy/health.svg)](https://phpackages.com/packages/sararzbn-queryspy)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2920.0k](/packages/voku-session2db)

PHPackages © 2026

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