定制 happytodev/phage-debug 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

happytodev/phage-debug

Composer 安装命令:

composer require happytodev/phage-debug

包简介

Phage Debug - Built-in debugging system for PHP development

README 文档

README

Built-in debugging system for PHP development with Phage. Simple and elegant debugging tool with zero configuration.

Features

  • 📝 Logging - Log messages with context
  • 🔍 Collapsible Variables - Inspect variables with expandable tree view
  • 🎨 Syntax Coloring - Color-coded display by type
  • 📦 Object Inspection - View properties (public/protected/private)
  • ⏱️ Performance Measurement - Measure execution time and memory
  • 🗄️ SQL Logging - Log database queries with bindings
  • Exception Handling - Capture and analyze exceptions
  • 📊 Table Display - Display data as formatted tables
  • 📡 HTTP Requests - Log HTTP requests and responses
  • 🔄 Stack Traces - Get detailed stack traces
  • Zero Configuration - Works out of the box
  • 📡 Real-time Updates - Live WebSocket connection to debug UI
  • 💾 Persistent History - SQLite database backend

Installation

Install via Composer:

composer require happytodev/phage-debug

Requirements

  • PHP 7.4 or higher
  • Phage debug server running on http://localhost:23517 (default)

Quick Start

1. Make sure the Phage debug server is running:

./phage debug:start

2. Use in your PHP code:

<?php

use Phage\Debug\Debug;

// Simple logging
Debug::log('Application started');
Debug::log('User data', $user);

// Dump variables with interactive tree view
Debug::dump($_GET, $_POST, $complexArray);

// Log queries
Debug::sql('SELECT * FROM users', [], 0.045);

// Log exceptions
try {
    // ...
} catch (Exception $e) {
    Debug::exception($e);
}

// Measure performance
Debug::measure('Database Query', function() {
    return User::all();
});

// Display as table
Debug::table($users, 'Active Users');

// Pretty-print JSON
Debug::json(['status' => 'success', 'data' => $data]);

3. Open the debug UI:

./phage debug:open

Or manually open: http://localhost:23517

UI Features

The debug UI displays:

Collapsible Arrays:

▶ Array(5)
  [0]: "item1"
  [1]: "item2"
  [id]: 123

Collapsible Objects:

▶ User(4 properties)
  $id (private): 123
  $name (private): "John Doe"
  $email (private): "john@example.com"
  $roles (protected): Array(2)
    [0]: "admin"
    [1]: "user"

Primitive Types:

string: "Hello World"
integer: 42
float: 3.14
boolean: true
null: null

Configuration

Configure globally in your bootstrap code:

use Phage\Debug\Debug;

Debug::config([
    'enabled' => true,
    'endpoint' => 'http://localhost:23517/api/payloads',
    'async' => true,           // Non-blocking requests
    'timeout' => 0.5,          // 500ms timeout
]);

Or configure individually:

Debug::setEndpoint('http://192.168.1.100:23517/api/payloads');
Debug::setOrigin('my-project');

API Reference

Logging & Dumping

  • Debug::log(...$messages) - Log messages with optional context
  • Debug::dump(...$vars) - Dump variables with full tree view

Measurement

  • Debug::measure($label, $callback) - Measure execution time and memory
  • Debug::sql($sql, $bindings, $time) - Log SQL queries with bindings
  • Debug::exception($throwable) - Log exceptions with stack trace

Data Display

  • Debug::table($data, $label) - Display data as formatted table
  • Debug::json($data, $label) - Pretty-print JSON
  • Debug::http($method, $url, $headers, $body, $duration) - Log HTTP requests

Utilities

  • Debug::trace($label) - Get current stack trace
  • Debug::enable() - Enable debugging
  • Debug::disable() - Disable debugging
  • Debug::isEnabled() - Check if debugging is enabled

Advanced Usage

Disable for Production

if (env('APP_DEBUG')) {
    Debug::enable();
} else {
    Debug::disable();
}

Custom Origin

// Defaults to composer.json "name" field
Debug::setOrigin('my-custom-project-name');

Remote Debugging

Connect to a remote Phage debug server:

Debug::setEndpoint('http://192.168.1.100:23517/api/payloads');
Debug::log('Log from remote client');

Synchronous Mode

By default, debug requests are non-blocking (async). Force synchronous mode:

Debug::config([
    'async' => false,  // Wait for responses
    'timeout' => 2.0,  // 2 second timeout
]);

How It Works

  1. Your PHP code calls Debug::log(), Debug::dump(), etc.
  2. The package serializes the data (arrays, objects, primitives) into a detailed structure
  3. A non-blocking HTTP POST request sends the data to the Phage debug server
  4. The server broadcasts the payload to connected WebSocket clients (the UI)
  5. The UI renders the data with interactive collapsible trees
  6. Data is also persisted in SQLite for history

Supported Types

  • Primitives: null, bool, int, float, string
  • Collections: array (with unlimited nesting)
  • Objects: Any PHP object (with property inspection)
  • Special: DateTime objects with formatted display

Recursion Limit

To prevent infinite loops with circular references, the package limits recursive depth to 10 levels. Deeper nesting is truncated with a [Max depth reached] indicator.

License

MIT License - see LICENSE file for details

Support

For issues, questions, or contributions:

Author

HappyToDev

happytodev/phage-debug 适用场景与选型建议

happytodev/phage-debug 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 happytodev/phage-debug 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-07