anil/dump 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

anil/dump

Composer 安装命令:

composer require anil/dump

包简介

A Laravel dump server package for intercepting and displaying dump output.

README 文档

README

Latest Version on Packagist Total Downloads Tests License

A Laravel package that intercepts dump() and dd() calls and streams them to a dedicated terminal server — keeping your browser responses clean while you debug.

Inspired by Symfony's var-dump-server, built for the Laravel ecosystem.

Features

  • Intercepts all dump() / dd() calls and forwards them to a running terminal server
  • Falls back to CLI or HTML output when the server is not running
  • Attaches request context (URI, method, controller) and a stack trace to every dump
  • Optional log channel support — write every dump to a Laravel log channel
  • Global helpers: dump_if(), dump_unless(), dd_if(), dd_unless()
  • DumpFake testing utility with rich PHPUnit assertions
  • Production guard — the handler is never registered when APP_ENV=production
  • Configurable clone depth and item limits via environment variables

Requirements

Dependency Version
PHP ^8.2
Laravel ^11.0 | ^12.0 | ^13.0
symfony/var-dumper ^7.0 | ^8.0

Installation

Install as a dev dependency (recommended — debug tooling should not ship to production):

composer require anil/dump --dev

If you need the dump server available in production (e.g. for staging environments or log-channel mirroring), install it as a regular dependency instead:

composer require anil/dump

The service provider is auto-discovered. Then run the install command to publish the config and add the required environment variables:

php artisan dump:install

This will:

  • Publish config/dump-server.php
  • Append DUMP_SERVER_HOST, DUMP_SERVER_ENABLED, and DUMP_SERVER_LOG_ENABLED to both .env and .env.example

Usage

1. Start the dump server

In a separate terminal, start the server before making requests:

php artisan dump:server

Output HTML instead of CLI output:

php artisan dump:server --format=html

2. Call dump() or dd() as usual

dump($user);
dump(['key' => 'value']);
dd($request->all());

When the server is running, output is captured and displayed in the server terminal — with request context and a stack trace — instead of inline in the browser.

When the server is not running, dump() falls back to normal CLI or HTML output.

Helper Functions

Four conditional helpers are available globally:

// Dump only when the condition is true
dump_if($user->isAdmin(), $user);

// Dump only when the condition is false
dump_unless($request->isJson(), $request->all());

// Die-and-dump only when the condition is true
dd_if(app()->isLocal(), $response);

// Die-and-dump only when the condition is false
dd_unless($feature->isEnabled(), $payload);

Configuration

Publish the config file manually if needed:

php artisan vendor:publish --tag=dump-server-config

config/dump-server.php:

return [
    // TCP host the server listens on
    'host' => env('DUMP_SERVER_HOST', 'tcp://127.0.0.1:9912'),

    // Set to false to disable the handler entirely in an environment
    'enabled' => env('DUMP_SERVER_ENABLED', true),

    // VarCloner limits — increase for deeply nested structures
    'max_depth' => env('DUMP_SERVER_MAX_DEPTH', 10),
    'max_items' => env('DUMP_SERVER_MAX_ITEMS', 2500),

    // Optionally mirror every dump to a log channel
    'log' => [
        'enabled' => env('DUMP_SERVER_LOG_ENABLED', false),
        'channel' => env('DUMP_SERVER_LOG_CHANNEL', 'stack'),
        'level'   => env('DUMP_SERVER_LOG_LEVEL', 'debug'),
    ],
];

Environment variables

Variable Default Description
DUMP_SERVER_HOST tcp://127.0.0.1:9912 TCP address the server binds to
DUMP_SERVER_ENABLED true Set to false to disable the handler
DUMP_SERVER_MAX_DEPTH 10 Maximum clone depth for nested objects
DUMP_SERVER_MAX_ITEMS 2500 Maximum number of items cloned
DUMP_SERVER_LOG_ENABLED false Mirror dumps to a log channel
DUMP_SERVER_LOG_CHANNEL stack Log channel to write to
DUMP_SERVER_LOG_LEVEL debug PSR-3 log level

Testing

The package ships with DumpFake, a drop-in test helper that captures dumps and provides PHPUnit assertions.

use Anil\Dump\Testing\DumpFake;

$fake = DumpFake::fake();

dump('hello');
dump(42);
dump(['a' => 1]);

// Assert a specific value was dumped
$fake->assertDumped('hello');

// Assert a value was NOT dumped
$fake->assertNotDumped('world');

// Assert nothing was dumped
$fake->assertNothingDumped();

// Assert the total number of dumps
$fake->assertDumpedCount(3);

// Assert using a custom callback
$fake->assertDumpedUsing(fn ($v) => is_array($v) && isset($v['a']));

// Retrieve all captured values
$dumped = $fake->getDumped();

// Restore the original handler when done
$fake->restore();

Running the test suite

composer test

Static Analysis

The package is analysed at PHPStan level 10 with Larastan:

composer analyse

Code Style

Formatting is enforced with Laravel Pint:

composer format       # fix
composer format:check # check only

Changelog

See CHANGELOG.md for release history.

License

The MIT License (MIT). See LICENSE for details.

anil/dump 适用场景与选型建议

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

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

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

围绕 anil/dump 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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