Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

RDebug - Real Debugger

Gitter License


1. Introduction

Rdebug is an open source tool chain that focusing on efficiency of daily developing, testing and debugging for developers. The code will be robust.

1.1 Background

As micro-service architecture makes services isomerous, easy-to-deploy and superbly extensible, large systems are divided into several micro services.

But, micro-service architecture is not a silver bullet. It has several drawbacks. One service is divided into several small services, test environment becomes hard to maintain. Unit test needs to mock downstream services. This will downgrade the efficiency of developing, and increase production bugs.

We do believe this industry needs an evolution.

1.2 Principle

Efficiency improvement, release cycle reduction, code quality improvement, production bug reduction

1.3 When to use

Suitable for old api refactoring that traffic have already been recorded.

Not suitable for new api or api that has no traffic recorded.

Support for new api is under investigation.

2. Quick Started

Traffic Recording

# Modify php-fpm config, set `clear_env = no`

# Compile &

# Start php-fpm with &
# Set environment first
$ export KOALA_SO=/path/to/ 
$ export KOALA_RECORD_TO_DIR=/path/to/your-save-recorded-session-dir
$ export LC_CTYPE="C"

# Recording
# macOS
$ DYLD_INSERT_LIBRARIES="/path/to/" DYLD_FORCE_FLAT_NAMESPACE="y" /path/to/sbin/php-fpm

# or, Linux
$ LD_PRELOAD="/path/to/" /path/to/sbin/php-fpm

Traffic Replaying

Three ways to replay: replay from source, replay by midi.phar, replay by composer vendor/bin.

# Source
$ git clone
$ cd rdebug/php/midi
$ sh
$ cd /path/to/your/project
$ /path/to/rdebug/php/midi/bin/midi run -f RECORD-SESSION-FILE

# Or, Phar
$ wget -O midi.phar -q
$ midi.phar run -f RECORD-SESSION-FILE

# Or, Composer global
$ composer global require rdebug/midi
$ cd /path/to/your/project
$ ~/.composer/vendor/bin/midi run -f RECORD-SESSION-FILE

# Or, Composer
$ cd /path/to/your/project
$ composer require rdebug/midi --dev
$ ./vendor/bin/midi run -f RECORD-SESSION-FILE

PHP Example

3. Technical Details

We are using real production traffic to test on non-production environment. So, the core features of Rdebug are traffic recording and traffic replaying.

  • Traffic Recording

    Recording production traffic, including RPC between micro-services. The most difficult part is to trace requests that will span multiple services.

  • Traffic Replaying

    Replaying recorded production traffic against non-production environment, mock downstream traffic based on traffic matching. The most difficult part is interception and traffic matching.


3.1 Koala & Koala-libc

Koala and Koala-libc is the engine of Rdebug.

Because the problems such as RPC tracing, libc interception that a traffic replaying system may concern is what a traffic recording system concerns. The traffic recording and replaying system shares the same engine.


Koala is written in Go, libc contains some c++ code for interception part which will complied to and

Koala support replaying and recording separately as well as simultaneously.

For more details: koala


koala-libc is written in C, and compiled to

Go does not support fork. To avoid problems bring by PHP-FPM fork worker, you need to inject into parent process of PHP. So that will forward requests libc intercepted to * when accept in child process

For more details: koala-libc

3.2 Midi

Midi is a traffic replay client for PHP using command line written in PHP. is embedded in Midi, and it can replay production traffic against new code, analyze test result, generate diff report, trace report, coverage report.

Midi support Xdebug.

For more details: midi

4. Compile

4.1 Requirement

Koala & Koala-libc

  • GCC >= 4.8
  • Go >= 1.8
  • Glide


  • macOS/Linux
  • PHP >= 7.0
  • Xdebug (Optional)
  • Composer (Optional)

4.2 Compile Koala-libc

$ cd koala-libc
$ sh

will generate ../output/libs/

4.3 Compile Koala

$ cd koala

# install depends
$ sh vendor

$ sh recorder

$ sh

will generate ../output/libs/ and ../output/libs/

4.4 Compile midi.phar

Before compile midi.pahr, recommend compile at your system and store in php/midi/res/replayer directory.

php/midi/res/replayer/ in repository is for macOS.

$ cd php/midi
$ sh

will generate ../output/bin/midi.phar

Default phar will not include DiPlugin plugin, which is an internal plugin of didi.

If your want to compile with DiPlugin plugin:

$ cd php/midi
$ sh midi-diplugin

5. Usage

5.1 Traffic Recording

Record traffic in file or Elastic.

Set environment variable KOALA_RECORD_TO_DIR to save record to specified dir

Inject so. Use DYLD_INSERT_LIBRARIES in macOs or LD_PRELOAD in Linux

For more details: Recorder

5.1.1 macOS Recording

$ DYLD_INSERT_LIBRARIES="/path/to/" DYLD_FORCE_FLAT_NAMESPACE="y" LC_CTYPE="C" KOALA_SO=/path/to/ KOALA_RECORD_TO_DIR=/tmp /usr/local/sbin/php-fpm

5.1.2 Linux Recording

LD_PRELOAD="/path/to/ /usr/lib64/" LC_CTYPE="C" KOALA_SO="/path/to/" KOALA_RECORD_TO_DIR=/tmp /usr/local/sbin/php-fpm

Koala support writing to Elastic by replacing KOALA_RECORD_TO_DIR with KOALA_RECORD_TO_ES which value is elastic write url

5.2 Traffic Replay

Traffic replaying is to replay recorded traffic in production against non-production environment. You need only to deploy your code w/o deploying downstream services.

Below is a simple example of replaying with '-f', which specified the file to replay.

5.2.1 Replay

# Source
$ /path/to/rdebug/php/midi/bin/midi run -f RECORD-SESSION-FILE

# Or, phar
$ midi.phar run -f RECORD-SESSION-FILE

# Or, composer vendor bin
$ ./vendor/bin/midi -f RECORD-SESSION-FILE

For more details: Replay

Use -v, -vv or -vvv for more verbose log.

5.2.2 Report

Use -R-T-C to generate:Replay report, Trace report, Coverage report




For more details: Midi

6. More

6.1 Translation

6.2 Documentation

6.3 Contribute

Any contributions are welcome. More Details

6.4 Contract

  • Add Weixin

  • QQ Group


6.5 License

Rdebug is licensed under the Apache 2.0 License. LICENSE

6.6 Contributors

Special thanks to TaoWen Developer of Koala & Koala-libc.

Thanks to all the people who contribute.