承接 saasscaleup/laravel-n-plus-one-detector 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

saasscaleup/laravel-n-plus-one-detector

Composer 安装命令:

composer require saasscaleup/laravel-n-plus-one-detector

包简介

Real-time detection and resolution of N+1 query issues for Laravel applications. Support now Laravel 11

README 文档

README

Laravel N+1 Query Detector

Real-time detection and resolution of N+1 query issues for Laravel applications. Provides detailed insights, advanced notifications, and a rich admin dashboard.

Perfect for solo developers and teams. Compatible with Laravel 5.5+ and PHP 7+.

Youtube · Twitter · Facebook · Buy Me a Coffee

Latest Stable Version Total Downloads License


banner

Laravel N+1 Query Detector

Laravel N+1 Query Detector is a powerful package designed to help you identify and resolve N+1 query problems in real-time. Perfect for individual developers and teams, this package enhances your application’s performance by catching inefficient queries before they impact your users.

✨ Features

  • Real-time N+1 Query Detection: Identify N+1 queries as they happen, ensuring your application remains performant.
  • Detailed Query Insights: Get detailed information about each detected N+1 query, including file line, the class and methods involved.
  • Advanced Notifications: Receive alerts via Slack, webhooks, or email, ensuring you never miss an important notification.
  • Rich Admin Dashboards: View all N+1 warnings in a comprehensive and user-friendly dashboard.
  • Suit for Teams and Solo Developers: Designed to be used by both solo developers and teams working collaboratively.

Requirements

  • PHP >= 7
  • Laravel >= 5.5

Installation

Install composer package (dev)

Via Composer - Not recommended for production environment

composer require --dev saasscaleup/laravel-n-plus-one-detector

Publish package's config, migration and view files

Publish package's config, migration and view files by running below command:

Try this command first

php artisan vendor:publish --provider="Saasscaleup\NPlusOneDetector\NPlusOneDetectorServiceProvider"

If you are getting this result:

No publishable resources for tag [].
Publishing complete.

Than try to this:

php artisan vendor:publish

and then enter the number of that represent the provider (in the example below the number is 14)

  [13] Provider: Saasscaleup\LogAlarm\LogAlarmServiceProvider
  [14] Provider: Saasscaleup\NPlusOneDetector\NPlusOneDetectorServiceProvider

> 14

Run migration command

Run php artisan migrate to create nplusone_warnings table.

php artisan migrate

Run route:cache command

Run php artisan migrate to make sure route cache will be purge becasue we are adding new route /n-plus-one-dashboard.

php artisan route:cache

Configuration

You can configure the package by editing the config/n-plus-one.php file. This file allows you to set the threshold for detecting N+1 queries, notification preferences, and more.

<?php

return [
    
    // Whether or not to enable the N+1 Detector
    'enabled' => env('NPLUSONE_ENABLED', true),
    
    // The number of queries below which no alert will be triggered
    'queries_threshold' => env('NPLUSONE_QUERIES_THRESHOLD', 50),
    
    // The number of queries below which no detector will be triggered
    'detector_threshold' => env('NPLUSONE_DETECTOR_THRESHOLD', 10),
    
    // The number in minutes a n+1 query will be stored in memory before being discarded. So it won't repeat itself
    'cache_lifetime' => env('NPLUSONE_CACHE_LIFETIME', 14400), // 10 days
      
    // Slack webhook url for N + 1 Detector
    'slack_webhook_url' => env('NPLUSONE_SLACK_WEBHOOK_URL', ''),

    // Custom webhook url for N + 1 Detector
    'custom_webhook_url' => env('NPLUSONE_CUSTOM_WEBHOOK_URL', ''),

    // notification email address for N + 1 Detector
    'notification_email' => env('NPLUSONE_NOTIFICATION_EMAIL', 'admin@example.com'), // also possible: 'admin@example.com,admin2@example.com'

    // notification email subject for N + 1 Detector
    'notification_email_subject' => env('NPLUSONE_NOTIFICATION_EMAIL_SUBJECT', 'N+1 Detector Notification'),

    // Dashboard Middleware for N + 1 Detector
    'dashboard_middleware' => env('NPLUSONE_DASHBOARD_MIDDLEWARE', ['web', 'auth']),

    // Dashboard Pagination for N + 1 Detector
    'dashboard_records_pagination' => env('NPLUSONE_DASHBOARD_RECORDS_PAGINATION', 10),

];

Usage

Real-time Detection

The package automatically listens to your database queries and detects N+1 issues in real-time. When an N+1 query is detected, it logs the query details and optionally sends notifications.

Admin Dashboard

Access the rich admin dashboard to view all N+1 warnings:

Route::get('/n-plus-one-dashboard', [NPlusOneDashboardController::class, 'index'])->name('n-plus-one.dashboard');

The dashboard provides a comprehensive view of all detected N+1 queries, including SQL statements, occurrences, locations, and suggested fixes.

banner

Notifications

Configure notifications to be sent via Slack, webhook, or email. Set your notification preferences in the config/n-plus-one.php file to stay informed about N+1 issues in your application.

    // Slack webhook url for N + 1 Detector
    'slack_webhook_url' => env('NPLUSONE_SLACK_WEBHOOK_URL', ''),

    // Custom webhook url for N + 1 Detector
    'custom_webhook_url' => env('NPLUSONE_CUSTOM_WEBHOOK_URL', ''),

    // notification email address for N + 1 Detector
    'notification_email' => env('NPLUSONE_NOTIFICATION_EMAIL', 'admin@example.com'), // also possible: 'admin@example.com,admin2@example.com'

Slack notification

slack

Webhook notification

webhook

Email notification

email

Advanced Features

Detailed Query Insights

The package provides detailed insights into each detected N+1 query, including the class and methods involved. This helps you quickly pinpoint the source of the problem and implement a fix.

License

Please see the MIT for more information.

Support 🙏😃

If you Like the tutorial and you want to support my channel so I will keep releasing amzing content that will turn you to a desirable Developer with Amazing Cloud skills... I will realy appricite if you:

  1. Subscribe to our youtube
  2. Buy me A coffee ❤️

Thanks for your support :)

saasscaleup/laravel-n-plus-one-detector 适用场景与选型建议

saasscaleup/laravel-n-plus-one-detector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.14k 次下载、GitHub Stars 达 48, 最近一次更新时间为 2024 年 07 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「laravel performance」 「laravel package」 「query optimization」 「database optimization」 「performance tuning」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 saasscaleup/laravel-n-plus-one-detector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 saasscaleup/laravel-n-plus-one-detector 我们能提供哪些服务?
定制开发 / 二次开发

基于 saasscaleup/laravel-n-plus-one-detector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 48
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 48
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-08