Aerial view of a toll plaza, seen from directly above. A wide motorway of pale concrete runs through dense green forest and fans out into nine lanes in front of a long, grey-blue roof, the lanes separated by white hatched markings. A few cars and lorries are on the road before and after the plaza, and every vehicle has to pass through one of the lanes beneath the roof.

Xdebug, PCOV, and turbocov see the same bytecode. They differ in how often they stop the executor to take a look: Xdebug at every instruction, PCOV at every instruction too but with less work, turbocov once per line. Each of these shortcuts is paid for with something that is no longer observed afterwards. I continue to collect code coverage data with Xdebug, advise against PCOV for new projects, and am waiting when it comes to turbocov.

Over the last few days I have been asked several times what I think of turbocov. In 2024 I answered the question “PCOV or Xdebug?” with Xdebug, after five years with PCOV, and gave the xdebug.mode setting and the uncertain future of PCOV as my reasons. That reasoning is not enough for a third extension. Anyone who chooses between the three should know where in the execution of bytecode each of them sits. So far I have only read turbocov and measured it for this article; I have not used it in a project of my own.

I restrict myself to line coverage. It is the only thing all three deliver. Everything that follows refers to PHP 8.6, Xdebug 3.6.0alpha1, PCOV 1.0.12, and turbocov 0.1.3.

The compiler assigns the line numbers

In “How PHP executes bytecode” I showed the instruction that compiled PHP code is made of, the struct zend_op. There was one of its fields I did not need there: lineno, the line of the source code that the compiler attributes the instruction to. For all three extensions, line coverage is the set of lineno values of the instructions that ran. None of them sees your source code.

Throughout this article I use one file with four small functions:

<?php declare(strict_types=1);

function label(int $weight): string
{
    return match ($weight) {
        1       => 'letter',
        2       => 'parcel',
        default => 'freight',
    };
}

function isEligible(
    bool $member,
    bool $coupon,
    bool $firstOrder,
): bool {
    return $member
        || $coupon
        || $firstOrder;
}

function firstPositive(array $values): ?int
{
    $result = null;

    foreach ($values as $value) {
        if ($value <= 0) {
            continue;
        }

        $result = $value;

        break;
    }

    return $result;
}

function limits(): array
{
    return [
        'bits' => PHP_INT_SIZE * 8,
        'size' => 1024 * 1024,
        'time' => time(),
    ];
}

As of PHP 8.6, OPcache prints the bytecode before the optimiser touches it when opcache.opt_debug_level=0x40010000 is set, and puts the line in front of every instruction. For isEligible() this looks as follows:

isEligible:
     ; (lines=11, args=3, vars=3, tmps=1)
     ; (before optimizer)
     ; /path/to/example.php:12-20
L0013 0000 CV0($member) = RECV 1
L0014 0001 CV1($coupon) = RECV 2
L0015 0002 CV2($firstOrder) = RECV 3
L0017 0003 T3 = JMPNZ_EX CV0($member) 0005
L0018 0004 T3 = BOOL CV1($coupon)
L0018 0005 T3 = JMPNZ_EX T3 0007
L0019 0006 T3 = BOOL CV2($firstOrder)
L0019 0007 VERIFY_RETURN_TYPE T3
L0019 0008 RETURN T3
L0020 0009 VERIFY_RETURN_TYPE
L0020 0010 RETURN null

Keep lines 18 and 19 in mind. When $member is true, instruction 0003 jumps to 0005, and $coupon is never evaluated. Instruction 0005 runs all the same, and it is on line 18. The same holds for line 19: $firstOrder is skipped, but the compiler has attributed the RETURN of the whole statement to that line. So there are two correct answers to the question of whether line 18 was executed, depending on whether you ask the bytecode or the source code.

Xdebug is called for every instruction

The engine allows an extension to register a handler of its own for an opcode. Xdebug does so as soon as xdebug.mode contains the value coverage, and it does so for every opcode but one. For about seventy opcodes the registration is written out in the source code, a loop takes care of the rest:

xdebug_set_opcode_handler(ZEND_JMP, xdebug_common_override_handler);
xdebug_set_opcode_handler(ZEND_JMPZ, xdebug_common_override_handler);
xdebug_set_opcode_handler(ZEND_JMPZ_EX, xdebug_common_override_handler);
xdebug_set_opcode_handler(ZEND_JMPNZ, xdebug_common_override_handler);

/* ... */

/* Override all the other opcodes so that we can mark when we hit a branch
 * start one */
for (i = 0; i < 256; i++) {
    if (i == ZEND_HANDLE_EXCEPTION) {
        continue;
    }
    if (!xdebug_isset_opcode_handler(i)) {
        xdebug_set_opcode_handler(i, xdebug_check_branch_entry_handler);
    }
}

When code is compiled, an opcode with such a handler no longer gets its own handler in opline->handler, it gets the one of ZEND_USER_OPCODE:

ZEND_VM_HANDLER(150, ZEND_USER_OPCODE, ANY, ANY)
{
    USE_OPLINE
    int ret;

    SAVE_OPLINE();
    ret = zend_user_opcode_handlers[opline->opcode](execute_data);
    opline = EX(opline);

    switch (ret) {
        case ZEND_USER_OPCODE_CONTINUE:
            ZEND_VM_CONTINUE();

        /* ... */

        case ZEND_USER_OPCODE_DISPATCH:
            ZEND_VM_DISPATCH(opline->opcode, opline);

        /* ... */
    }
}

Every instruction of your code now takes the same detour. The executor jumps into the handler of ZEND_USER_OPCODE, that handler calls the handler of Xdebug through a function pointer, and Xdebug answers with ZEND_USER_OPCODE_DISPATCH. Only then does the engine look up which handler would have been responsible, and calls it as a function. Little is left of the dispatch models from the article on the executor in this mode of operation: the actual handler is no longer jumped to, it is called through a function pointer from one single place, as in the CALL model, and two more calls come before that.

What Xdebug does in its handler has been little for line coverage since version 3.6:

static void xdebug_count_line(zend_string *filename, int lineno)
{
    xdebug_coverage_file *file = fetch_file(filename);

    xdebug_mset_add(file->runtime.hit_lines, lineno, COV_BIT_HIT);
}

/* ... */

static int xdebug_common_override_handler(XDEBUG_OPCODE_HANDLER_ARGS)
{
    zend_op_array *op_array;
    const zend_op *cur_opcode;

    if (!XG_COV(code_coverage_active)) {
        return xdebug_call_original_opcode_handler_if_set(execute_data->opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU);
    }

    op_array = &execute_data->func->op_array;
    cur_opcode = execute_data->opline;

    if (!op_array->reserved[XG_COV(code_coverage_filter_offset)]) {
        int      lineno;

        lineno = cur_opcode->lineno;

        xdebug_print_opcode_info(execute_data, cur_opcode);
        xdebug_count_line(op_array->filename, lineno);
    }

    return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU);
}

xdebug_count_line() sets one bit in a byte that belongs to the line. That is the result of the rewrite Derick Rethans made with pull request #774: up to Xdebug 3.5 every line had a structure of its own in a hash table that was searched on every hit. xdebug_print_opcode_info() belongs to branch coverage and runs even when you only want line coverage.

It does not end there. Xdebug has the compiler put an EXT_STMT in front of every statement, an additional instruction that does nothing but call the statement handler of the extension. Xdebug also replaces zend_execute_ex, the function pointer through which the engine enters the executor. What that does to the C stack is shown by the figure in the section “The whole executor is a loop”. And for the duration of the request Xdebug sets opcache.optimization_level to 0, the value I used in “How PHP optimises bytecode” to switch the optimiser off for measuring. The JIT is off anyway as soon as an extension replaces zend_execute_ex or registers a handler for an opcode.

That is expensive, and it buys something. Xdebug sees every instruction that runs, and it sees the bytecode the way the compiler produced it. Branch and path coverage, which only Xdebug delivers, build on this, and so does the distinction between code that was not executed and code that cannot be reached.

PCOV replaces the loop of the executor

PCOV does not register a single handler. It replaces zend_execute_ex with a loop of its own that asks three questions before every instruction:

static zend_always_inline int php_pcov_trace(zend_execute_data *execute_data) {
    if (PCG(enabled)) {
        if (php_pcov_wants(EX(func)->op_array.filename) &&
            !php_pcov_ignored_opcode(EX(opline)->opcode) &&
            !php_pcov_has(EX(func)->op_array.filename, EX(opline)->lineno)) {

            php_coverage_t *coverage = php_pcov_create(execute_data);

            /* ... */
        }
    }

    return zend_vm_call_opcode_handler(execute_data);
}

/* ... */

void php_pcov_execute_ex(zend_execute_data *execute_data) {
    int zrc = 0;

    while (1) {
        zrc = php_pcov_trace(execute_data);

        if (zrc != SUCCESS) {
            if (zrc < SUCCESS) {
                return;
            }
            execute_data = EG(current_execute_data);
        }
    }
}

Is the file below pcov.directory? Is the opcode on the list of those that do not make a line executable? Has this line of this file been recorded already? Only when all three answers fit does PCOV create an entry. After that, zend_vm_call_opcode_handler() calls the handler of the instruction.

So PCOV is there at every instruction as well, and there is no JIT with PCOV either; it simply does less while it is there. It does not have the compiler insert EXT_STMT instructions, it leaves the optimiser of OPcache switched on, and it remembers exactly one hit for each line. For files outside pcov.directory it stops at the first of the three questions. Which lines of a file are executable at all is something PCOV only computes when the data is collected, from the control flow graph that the engine keeps ready for the optimiser.

turbocov removes its probes after the first hit

turbocov is by Jan Nedbal, and its first commit is dated 16 November 2026. It turns the order around. Xdebug and PCOV stand at the loop and check at every instruction whether they have to record something. turbocov writes into the bytecode at compile time at which instructions it wants to be called, and leaves the loop alone.

After a file that falls under turbocov.collect_paths has been compiled, turbocov walks the basic blocks of every function. At the first instruction of each line of a block it remembers the handler stored in opline->handler and puts the handler of ZEND_USER_OPCODE there instead, the same one through which Xdebug is called. That is the probe. When it is reached, the engine ends up here:

static int tc_probe_handler(zend_execute_data *execute_data)
{
    const zend_op *opline = EX(opline);
    zend_function *func = EX(func);
    tc_unit *unit;
    tc_probe *probe;
    uint32_t number;

    /* ... */

    unit = func->op_array.reserved[tc_slot];

    /* ... */

    number = unit->index[opline - unit->opcodes];

    /* ... */

    probe = &unit->probes[number - 1];

    /* ... */

    ((zend_op *) opline)->handler = probe->handler;
    tc_record(unit, number - 1);

    return ZEND_USER_OPCODE_CONTINUE;
}

The last three statements are the ones that matter. The probe puts the original handler back, records the hit, and returns ZEND_USER_OPCODE_CONTINUE. The engine then executes the same instruction again, this time with its own handler. From then on the line runs as if turbocov were not loaded, in a loop with a million iterations just as with a single one. Only when PHPUnit collects the data after a test does \turbocov\stop() arm the probes that were hit again.

The path of an instruction with Xdebug, with PCOV, and with turbocov
With Xdebug, every instruction goes through ZEND_USER_OPCODE into the handler of Xdebug and from there into its own. PCOV calls every instruction from its own loop. With turbocov, only the first execution of a line takes the detour: the probe puts the original handler back (dashed), and after that opline->handler leads straight to it.

The cost therefore depends on the number of distinct lines a test touches, and no longer on the number of instructions it executes. The price for that is in the list of things turbocov cannot work with. It writes into bytecode that it must not share with anybody. That is why it only runs on the command line, not under PHP-FPM, not on Windows, and only in one thread. It refuses to work when the JIT is on, when OPcache is operated with opcache.file_cache, opcache.preload, or opcache.protect_memory, and when the optimiser is switched on, because the optimiser removes instructions that a probe would have to sit on. It supports PHP 8.4 to PHP 8.6 and cannot be loaded together with Xdebug or PCOV. The conditions that concern OPcache and other extensions are checked by turbocov itself, and it stops with a message rather than deliver wrong data.

turbocov is the first extension to use the support for custom code coverage drivers that PHPUnit and php-code-coverage have had since PHPUnit 13.3. The project ships the driver itself as the package shipmonk/turbocov-phpunit, and you name its class in the XML configuration file with the driver attribute of the <coverage> element. I am glad that the project found this interface, and it confirms to me that it works in the field. I will therefore not offer a driver for turbocov of the kind php-code-coverage ships for Xdebug and PCOV, because it is not necessary.

Hot loops show the largest gap

I measured with the test suite of my raytracer project, which I already used for the benchmark in the old article. Its 177 tests do almost nothing but compute: 554 executable lines in 34 files, most of which run very often. With code like this it matters most whether an extension is there at every instruction or only at the first visit to a line.

Run time of the test suite without code coverage, with turbocov, with PCOV, and with Xdebug
Mean of five runs after one warm-up run.

Without code coverage the suite takes 9.8 seconds. With turbocov it takes 10.1 seconds, and that difference is smaller than the spread between the runs. With PCOV it takes 22.7 seconds, 2.3 times as long, and with Xdebug 76.6 seconds, 7.8 times as long.

For this suite, the choice of the extension makes no difference to the result. php-code-coverage counts 554 executable lines, and all three extensions report the same 553 of them as executed. The suite covers almost everything, and where every line is executed completely, the extensions have nothing to disagree about. They disagree about code that only runs in part, and that is the code you open a report for in the first place.

These numbers hold for this suite on this machine. The extensions only prolong the time PHP spends executing bytecode. If your suite mostly waits for a database or for the file system, the gap is smaller with all three. They cannot be compared with the numbers in the old article, because there PHP 8.5 and Xdebug 3.5 ran on a different machine with an older state of the suite.

I measured with hyperfine on an Intel Core i9-10900X under Fedora 45, with PHP 8.6.2-dev, PHPUnit 13.5.1, and php-code-coverage 14.6.0. In all runs OPcache is switched on, the optimiser is switched off with opcache.optimization_level=0, and the JIT is off. PHPUnit writes the data to a file with --coverage-php and generates no report. PCOV is the state of the development branch as of November, because version 1.0.12 cannot be compiled with PHP 8.6.

One file, five answers

I executed the file from the beginning with label(1), isEligible(true, false, false), firstPositive([0, 3, 5]), and limits() and asked the extensions directly, without PHPUnit in between. 1 means executed, -1 executable and not executed, a dash that the extension does not know the line:

Raw data of the extensions for selected lines of example.php. Except in the column “PCOV with optimiser”, the optimiser of OPcache is switched off.
Line Xdebug 3.6 Xdebug with #1112 PCOV PCOV with optimiser turbocov
6: 1 => 'letter', 1 1 1 1 1
8: default => 'freight', 1 1 1 1 -1
10: } -1 -1 – – –
17: return $member 1 1 1 1 1
18: || $coupon -1 1 1 -1 -1
19: || $firstOrder; 1 1 1 1 -1
28: continue; 1 1 1 – 1
33: break; 1 1 1 – 1
42: 'bits' => PHP_INT_SIZE * 8, 1 1 1 1 1
43: 'size' => 1024 * 1024, – – – – –

No two of the five columns are the same, and each one is a different answer to the question of which instruction counts for a line.

None of the extensions knows line 43, although it contains an expression. The compiler computed 1024 * 1024 and wrote the result into the instruction that builds the array, and that instruction it attributed to line 42:

L0042 0000 T0 = INIT_ARRAY 3 int(64) string("bits")
L0042 0001 T0 = ADD_ARRAY_ELEMENT int(1048576) string("size")
L0044 0002 INIT_FCALL 0 80 string("time")
L0044 0003 T1 = DO_ICALL
L0044 0004 T0 = ADD_ARRAY_ELEMENT T1 string("time")
L0044 0005 VERIFY_RETURN_TYPE T0
L0044 0006 RETURN T0

Line 8 is the case turbocov advertises itself with. label(1) does not reach the default arm, and yet Xdebug and PCOV report the line as executed:

L0005 0001 MATCH CV0($weight) 1: 0002, 2: 0004, default: 0006
L0006 0002 T2 = QM_ASSIGN string("letter")
L0006 0003 JMP 0008
L0007 0004 T2 = QM_ASSIGN string("parcel")
L0007 0005 JMP 0008
L0008 0006 T2 = QM_ASSIGN string("freight")
L0008 0007 JMP 0008
L0008 0008 VERIFY_RETURN_TYPE T2
L0008 0009 RETURN T2

Instructions 0008 and 0009 end the match expression and return its result. The compiler attributed them to the line of the last arm, and they run on every call. turbocov recognises instructions that only pass a value on and does not put a probe on them when the line also contains an operand. For the same reason it reports lines 18 and 19 as not executed. In this example that is the answer I expect as a reader of the source code.

The columns for Xdebug differ in line 18. XDEBUG_CC_UNUSED marks a line as executable for almost every opcode, but Xdebug 3.6.0alpha1 only counts it as executed for the opcodes that are registered individually. JMPNZ_EX is not one of them, and so a line that holds nothing but this jump stays at -1, no matter which test executes it. The open pull request #1112 names 18 opcodes that can be alone on a line and for which this is the case, and makes the loop at the end of the registration count for every opcode that makes a line executable. This does not make Xdebug measurably slower: the raytracer suite runs in 74.7 seconds with the pull request and in 76.1 seconds on the commit it builds on, and that difference lies within the spread. After that, Xdebug agrees with PCOV on all lines that both know. For line 18 this means: executed, although $coupon was not evaluated, because that is what the bytecode says.

Lines 10, 20, 37, and 46, the closing braces of the functions, are known to Xdebug only. They hold the RETURN null that the compiler appends to every function. PCOV and turbocov only put into their list of executable lines what the control flow graph shows to be reachable, and after a return this end is not reachable.

PCOV and turbocov observe less, and that is where the speed comes from

The column “PCOV with optimiser” is the one that bothers me most about PCOV. With the optimiser switched on, lines 28 and 33 are missing. They are not reported as not executed, they have disappeared from the data. In the bytecode, continue and break are a JMP each, here instructions 0006 and 0008:

L0027 0004 T5 = IS_SMALLER_OR_EQUAL CV2($value) int(0)
L0027 0005 JMPZ T5 0007
L0028 0006 JMP 0003
L0031 0007 ASSIGN CV1($result) CV2($value)
L0033 0008 JMP 0010
L0026 0009 JMP 0003
L0026 0010 FE_FREE T4

The optimiser inverts the conditional jump so that it no longer needs the JMP behind it, and it removes a JMP that only leads to the next instruction:

firstPositive:
     ; (lines=10, args=1, vars=3, tmps=2)
     ; (after optimizer)
     ; /path/to/example.php:22-37
0000 CV0($values) = RECV 1
0001 CV1($result) = QM_ASSIGN null
0002 T3 = FE_RESET_R CV0($values) 0007
0003 FE_FETCH_R T3 CV2($value) 0007
0004 T4 = IS_SMALLER_OR_EQUAL CV2($value) int(0)
0005 JMPNZ T4 0003
0006 CV1($result) = QM_ASSIGN CV2($value)
0007 FE_FREE T3
0008 VERIFY_RETURN_TYPE CV1($result)
0009 RETURN CV1($result)

Before the optimiser the function had fifteen instructions, afterwards it has ten, and none is left for lines 28 and 33. Line 18 looks different in this column as well: in isEligible() the optimiser makes the first jump lead straight to the RETURN, so that the jump on line 18 no longer runs. In “How PHP optimises bytecode” I showed how whole branches disappear this way. PCOV measures the optimised bytecode because it does not switch the optimiser off. That saves run time, and it makes the code coverage depend on a setting in php.ini. The issue about this has been open since July 2023.

The second simplification of PCOV is the question “recorded already?”. It turns every further execution of a line into a few lookups in hash tables instead of a new entry, and it settles that PCOV can never say how often a line ran. The third is pcov.directory: what lies outside it does not exist for PCOV.

turbocov continues down the same road. A probe that removes itself after the first hit cannot count, and it does not see what happens after it on the same line either. Because only one instruction per line and block is still observed, turbocov has to decide at compile time which instruction stands for the line. For multi-line expressions this decision is, as seen above, better than that of Xdebug and PCOV. It is a heuristic about what the compiler of PHP currently does, though, and turbocov itself documents where it is off: the test 029-line-shapes.phpt records as its expected result that the first arm of a match without a jump table counts as not executed when PHP checks its condition, and that a duplicate match arm, which PHP can never reach, is reported as executed. That these cases are written down in a test, and not only in an issue, speaks for the project.

For line coverage, Xdebug delivers only 1 or -1 today as well. It is the only one of the three extensions that could deliver more, though, because it sees every instruction. The open pull request #1097 adds XDEBUG_CC_HIT_COUNT and with it reports how often a line was entered. Neither the question “recorded already?” nor a probe that removes itself allows for that.

PHP 8.6 was meant to correct the line numbers and does not

That the end of a match expression ends up on the line of its last arm has been reported as a bug in PHP: php/php-src#18985. In July 2026 a correction went into the development branch of PHP 8.6, with which the compiler restores the line number when it is done with a subexpression. In August it was reverted before the second beta, with the remark that the problem was to be solved in a different way. The test for it is still in the source code of PHP and is marked as an expected failure.

What remains of this change is the flag I produced the dumps for this article with. What also remains is the situation all three extensions are in: which line an instruction is attributed to is not specified anywhere and can change with every version of PHP. The line numbers in the bytecode are there for error messages and stack traces, and for those it is enough when they are roughly right. turbocov works around this attribution with its heuristics, Xdebug and PCOV pass it on.

Numerator and denominator now come from the same bytecode

Line coverage is a fraction. The extension delivers the numerator. The denominator, the executable lines, is something phpunit/php-code-coverage also needs for files that no test has loaded, which is why it determines it itself. Until recently this was only possible from the syntax, with PHP-Parser. That analysis had to predict which lines the compiler attributes instructions to, and each of the deviations in the table above is a case it has to know about in order to do so. As a rule, such a case only became known through an issue about a line that no test could turn green.

Since php-code-coverage 14.6, which was released together with PHPUnit 13.5, the library reads the executable lines with PHP 8.6 from the same dump you have seen above. How this works in detail is described in the section “Executable lines are stated by the bytecode” of the article on PHPUnit 13.5. What matters for the choice of the extension is the condition: OPcache has to compile the code that is executed in the same way as the code that is analysed.

$ php -d opcache.enable_cli=1 \
      -d opcache.optimization_level=0 \
      -d opcache.file_update_protection=0 \
      vendor/bin/phpunit \
      --coverage-html build/coverage

With these settings the column “PCOV with optimiser” no longer exists, because the optimiser is then off. A line counts as executable when it has an instruction that both Xdebug and PCOV report, except for the appended RETURN. From the syntax, php-code-coverage counts 19 executable lines in the example file, from the bytecode 16: lines 41, 43, and 45, to which the compiler attributes no instruction, drop out. The question of whether line 18 was executed remains open, because it is part of the numerator.

I am staying with Xdebug

Xdebug has been collecting code coverage data for PHP for over 20 years. It observes the most, and what it reports I can retrace in the dump, instruction by instruction. Where it is off, as with the lines that hold nothing but a JMPNZ_EX, that can be fixed in one place. The numbers PHPUnit prints in my projects therefore continue to come from Xdebug.

I would no longer set up PCOV for a new project. The last released version is from December 2024 and cannot be compiled with PHP 8.6. The fix for that has been in the development branch since November, which by now holds sixteen commits without a release. Of the 26 open issues, 21 were opened by users and have never received a reply from a maintainer; the oldest is from February 2020. That is why I measured the development branch of PCOV for this article. If your distribution ships a patched package, PCOV works today. Whether that will still be true for PHP 8.7 I do not know.

The code of turbocov is well thought out. The idea of letting the bytecode do the work instead of standing at the loop holds up, the tests record the inconvenient results too, and the extension would sooner refuse to work than run in an environment it does not understand. For numbers I rely on, though, I do not use anything that is not yet three weeks old. turbocov had four releases by 4 December, and two of them changed which lines it reports as executed. Every such change shifts what your report shows as covered. An extension that writes into the bytecode and relies on details of the compiler also has to show that it survives the next version of PHP. I will look at turbocov again in a few months.

Whether you want to wait that long depends on what code coverage costs you today. If your suite takes a few minutes with Xdebug, waiting costs you nothing. If it runs for an hour with Xdebug and for eight minutes without code coverage, then turbocov is a calculation you may do differently from me. In that case, have Xdebug run alongside at least occasionally and compare the lines before you trust a threshold in your pipeline.