mconsult/anfi-debug
Composer 安装命令:
composer require mconsult/anfi-debug
包简介
A Laravel package for caching and viewing debug variables in Octane apps.
README 文档
README
This package provides a custom debugging solution for Laravel applications using Octane, where traditional debugging tools like Xdebug might not be available. It allows developers to cache variables and view them in a modern, user-friendly web interface that updates every 5 seconds.
Table of Contents
- Introduction
- Features
- Installation
- Configuration
- Usage
- Full Example
- Security Considerations
- Customization
- Compatibility
- License
- Contributing
- Contact
Introduction
This package offers a custom debugging solution for Laravel applications running with Octane, allowing developers to cache variables and display them in a modern, user-friendly web interface that automatically updates every 5 seconds.
Features
- Cache Variables: Allows you to cache any variables for debugging purposes.
- User-Friendly Web Interface: View cached variables in a modern and easy-to-use web interface.
- Automatic Refresh: The interface updates every 5 seconds to display the latest values.
- Easy Installation: Simple installation via Composer.
- Laravel Compatibility: Supports Laravel 8.x, 9.x, 10.x, and 11.x.
Installation
Step 1: Require the package using Composer.
composer require mconsult/anfi-debug
Note: Ensure your composer.json includes the repository if necessary.
Step 2: Publish the package assets.
php artisan vendor:publish --provider="ANFI\DebugPackage\DebugServiceProvider" --tag="public" --tag="views"
This command will copy the CSS files to your public directory and the views to your resources/views/vendor directory.
Configuration
No additional configuration is required. The package automatically registers its Service Provider through Laravel's package discovery.
Usage
Cache Variables with _debug()
Use the global _debug() function to cache variables for debugging.
Example:
// Cache variables $key = _debug([ 'variable1' => $value1, 'variable2' => $value2, // Add as many variables as needed ]);
-
Parameters:
array $variables: An associative array of variables to cache.string $key(optional): A custom key for the cache entry.
-
Returns:
string: The key used to store the variables in the cache.
Using a Custom Key:
$key = _debug($variables, 'my-custom-key');
Remove Cached Variables with _forget()
To remove cached variables, use the global _forget() function.
Example:
$success = _forget($key); if ($success) { echo "Cache key '{$key}' has been removed."; } else { echo "Cache key '{$key}' does not exist."; }
-
Parameters:
string $key: The key of the cached variables to remove.
-
Returns:
bool:trueif the key existed and was removed,falseotherwise.
View Cached Variables
Navigate to the following URL in your browser to view the cached variables:
http://your-app-url/debug/{key}
- Replace
{key}with the key returned by the_debug()function.
Example:
http://localhost:8000/debug/debug-614c1b5e5f8b
The interface will display the cached variables and automatically refresh every 5 seconds to reflect any changes.
Full Example
Here's a complete example of how to use the package:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ExampleController extends Controller { public function index() { $data = [ 'user' => auth()->user(), 'settings' => config('app.settings'), ]; // Cache variables for debugging $key = _debug($data); // Now, visit http://your-app-url/debug/{$key} to view the variables return view('welcome'); } public function clearDebug() { $key = 'debug-614c1b5e5f8b2'; // Replace with your actual key $success = _forget($key); if ($success) { return redirect()->back()->with('status', "Debug cache '{$key}' has been cleared."); } else { return redirect()->back()->with('status', "Debug cache '{$key}' does not exist."); } } }
Security Considerations
- Do Not Use in Production: Ensure that the debug routes are not accessible in production environments, as they may expose sensitive data.
- Route Protection: Consider protecting the debug routes with authentication or by restricting access to certain IP addresses.
Customization
- CSS Styling: You can modify the CSS file located at
public/vendor/debug-package/css/debug.cssto change the appearance of the debug interface. - Views: The views are published to
resources/views/vendor/debug-package. Feel free to customize them as needed.
Compatibility
- Laravel Versions: This package supports Laravel 8.x, 9.x, 10.x, and 11.x.
- PHP Versions: Requires PHP 8.0 or higher.
License
This package is open-sourced software licensed under the MIT license.
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss changes.
Contact
If you have any questions or need support, please open an issue on the GitHub repository.
mconsult/anfi-debug 适用场景与选型建议
mconsult/anfi-debug 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 693 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mconsult/anfi-debug 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mconsult/anfi-debug 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 693
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-02-11