定制 mougrim/php-xdebug-proxy 二次开发

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

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

mougrim/php-xdebug-proxy

Composer 安装命令:

composer create-project mougrim/php-xdebug-proxy

包简介

Xdebug (dbgp) proxy

README 文档

README

This is expandable dbgp xdebug proxy based on amphp.

The idea is described in the document Multi-user debugging in PhpStorm with Xdebug and DBGp proxy.

The main benefit is that this proxy is written in php - the language you know.

Latest Stable Version Latest Unstable Version License Unit tests status

Installation

This package can be installed as a Composer project:

composer.phar create-project mougrim/php-xdebug-proxy

Or dependency:

composer.phar require mougrim/php-xdebug-proxy --dev

For parse XML you should install ext-dom.

For write logs by default you should install amphp/log (use --dev if you installed php-xdebug-proxy as dependency):

composer.phar require amphp/log '^1.0.0'

Run

You can run next command:

bin/xdebug-proxy

The proxy will be run with default config:

Using config path /path/to/php-xdebug-proxy/config
[2019-02-14 10:46:24] xdebug-proxy.NOTICE: Use default ide: 127.0.0.1:9000 array ( ) array ( )
[2019-02-14 10:46:24] xdebug-proxy.NOTICE: Use predefined ides array (   'predefinedIdeList' =>    array (     'idekey' => '127.0.0.1:9000',   ), ) array ( )
[2019-02-14 10:46:24] xdebug-proxy.NOTICE: [Proxy][IdeRegistration] Listening for new connections on '127.0.0.1:9001'... array ( ) array ( )
[2019-02-14 10:46:24] xdebug-proxy.NOTICE: [Proxy][Xdebug] Listening for new connections on '127.0.0.1:9002'... array ( ) array ( )

So by default proxy listens 127.0.0.1:9001 for ide registration connections and 127.0.0.1:9002 for xdebug connections, use 127.0.0.1:9000 as default IDE and predefined IDE with key idekey.

Config

If you want to configure listening ports, etc., you can use custom config path. Just copy config directory to your custom path:

cp -r /path/to/php-xdebug-proxy/config /your/custom/path

There are 3 files:

  • config.php:
    <?php
    return [
        'xdebugServer' => [
            // xdebug proxy server host:port
            'listen' => '127.0.0.1:9002',
        ],
        'ideServer' => [
            // if proxy can't find ide, then it uses default ide,
            // pass empty string if you want to disable default ide
            // defaultIde is useful when there is only one user for proxy
            'defaultIde' => '127.0.0.1:9000',
            // predefined ide list in format 'idekey' => 'host:port',
            // pass empty array if you don't need predefined ide list
            // predefinedIdeList is useful when proxy's users aren't changed often,
            // so they don't need to register in proxy each proxy restart
            'predefinedIdeList' => [
                'idekey' => '127.0.0.1:9000',
            ],
        ],
        'ideRegistrationServer' => [
            // host:port for register ide in proxy
            // pass empty string if you want to disable ide registration
            'listen' => '127.0.0.1:9001',
        ],
    ];
  • logger.php: you can customize a logger, the file should return an object, which is instance of \Psr\Log\LoggerInterface;
  • factory.php: you can customize classes, which are used in proxy, file should return object, which is instanceof Factory\Factory.

Then change configs and run:

bin/xdebug-proxy --configs=/your/custom/path/config

Extending

As mentioned above you can customize classes using your custom factory, which implements Factory\Factory. By default Factory\DefaultFactory factory is used.

The most powerful are the request preparers. You can override Factory\DefaultFactory::createRequestPreparers(). It should return an array of objects which implement RequestPreparer\RequestPreparer interface.

Request preparers will be called:

  • on request to ide from first to last
  • on request to xdebug from last to first

You can use request preparer for example for changing path to files (in break points and execution files).

Good example of the request preparer is RequestPreparer\SoftMocksRequestPreparer. You can see its usage in Factory\SoftMocksFactory.

Using with soft-mocks

For soft-mocks you can use softMocksConfig config directory:

bin/xdebug-proxy --configs=/path/to/php-xdebug-proxy/softMocksConfig

If you you want to provide path to custom soft-mocks init script, then copy softMocksConfig and change config.php:

...
    'softMocks' => [
        // if empty string, then vendor/badoo/soft-mocks/src/init_with_composer.php is used
        'initScript' => '/your/custom/init-script.php',
    ],
...

For more information see doc in soft-mocks project.

Thanks

Many thanks to Eelf for proxy example smdbgpproxy.

Thanks to Dmitry Ananyev for help with docs.

mougrim/php-xdebug-proxy 适用场景与选型建议

mougrim/php-xdebug-proxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.92k 次下载、GitHub Stars 达 90, 最近一次更新时间为 2018 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 mougrim/php-xdebug-proxy 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 91
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 90
  • Watchers: 5
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-20