rayzenai/ray
Composer 安装命令:
composer require rayzenai/ray
包简介
A lightweight Ray-like debugging tool for Laravel applications
README 文档
README
A lightweight Ray-like debugging tool for Laravel applications with a web-based debug viewer.
Features
ray()helper function for quick debugging- Automatic slow query logging (configurable threshold)
- Request profiling middleware (N+1 detection, memory usage)
- Mail driver that records sent emails to the viewer (great for tests)
- Web-based debug viewer at
/debug/ray - Color-coded entries (red, orange, yellow, green, blue)
- Configurable access control via email whitelist
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
composer require rayzenai/ray
Configuration
Publish the config file:
php artisan vendor:publish --tag=ray-config
This creates config/ray.php:
return [ // Define allowed users by email // Use ['*'] to allow all authenticated users 'allowed_emails' => [ // '*', // 'admin@example.com', ], // User model configuration (for apps with custom user tables) 'user_model' => \App\Models\User::class, 'user_email_field' => 'email', // Queries slower than this (ms) are auto-logged 'slow_query_threshold' => 100, // Max debug entries to keep 'max_entries' => 100, // Storage location 'storage_path' => storage_path('logs/ray-debug.json'), ];
Usage
Basic Debugging
// Simple debug ray($variable); // With label — when two arguments are passed, the first becomes the label ray('user data', $user); // With colors ray($data)->red(); ray($data)->green(); ray($data)->blue(); ray($data)->yellow(); ray($data)->orange(); ray($data)->purple(); // Chained ray($data)->label('My Label')->green(); // Pause — highlights the entry as paused (orange) so it stands out in the viewer ray($data)->pause(); // Inline — log and return the original value so you can wrap an expression $user = ray($repository->find($id))->label('user')->value();
Static Methods
// Semantic logging Ray::error($data); // Red Ray::warning($data); // Yellow Ray::success($data); // Green Ray::info($data); // Blue // Performance Ray::measure('label'); // Start timer // ... code ... Ray::measure('label'); // Stop & log elapsed time Ray::memory(); // Log memory usage // Debugging Ray::trace(); // Log stack trace Ray::caller(); // Log caller info // Query logging Ray::showQueries(); // Start logging all queries Ray::showSlowQueries(50); // Log queries > 50ms Ray::stopQueries(); // Stop logging Ray::querySummary(); // Get query stats
Counter
// Count iterations foreach ($items as $item) { Ray::count('loop'); // Increments each call } Ray::resetCount('loop'); // Reset counter
Die & Dump
ray($data)->die(); // Log and exit // Or use helper rayDie($data, 'label');
Request Profiler Middleware
Add the middleware to log slow requests and detect N+1 queries:
// app/Http/Kernel.php protected $middlewareGroups = [ 'web' => [ // ... other middleware \RayzenAI\Ray\Middleware\RayRequestProfiler::class, ], ];
The profiler automatically logs:
- Requests taking > 100ms
- Requests using > 25MB memory
- N+1 query detection (same query 3+ times)
Mail Driver
Ray ships a Symfony mailer transport that records every outgoing email to the debug viewer instead of sending it. Perfect for inspecting mails generated by tests or local seeders.
Add it to config/mail.php:
'mailers' => [ // ... 'ray' => [ 'transport' => 'ray', ], ],
Then point your environment at it (typically in .env.testing or phpunit.xml):
MAIL_MAILER=ray
Recorded mails show up under the Mail tab at /debug/ray with full headers, an HTML preview (rendered in a sandboxed iframe), the text alternative, and an attachment summary. The transport itself works in any environment — only the viewer is gated to local.
Debug Viewer
Once installed, the package automatically registers the dashboard route. Open it in your browser at:
http://your-app.test/debug/ray
The route is registered with the web middleware group under the debug/ray prefix, and is only accessible in the local environment. Access is further restricted by the allowed_emails config (see Security).
Features:
- Tabs: Debug, Mail, Requests, Queries
- Color filters
- Search
- Auto-refresh toggle
- Expand/collapse entries
- Copy to clipboard
- Delete individual entries or clear all
Security
The package only works in local environment. Access is controlled by:
- Empty config - Shows error message prompting configuration
- Wildcard
['*']- Allows all authenticated users - Email list - Only specified emails can access
License
MIT
rayzenai/ray 适用场景与选型建议
rayzenai/ray 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 1.87k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rayzenai/ray 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rayzenai/ray 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04