PHPackages                             o0h/astop - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. o0h/astop

ActivePhp-ext[Debugging &amp; Profiling](/categories/debugging)

o0h/astop
=========

A PHP extension that intercepts the compilation pipeline and prints the AST and opcodes

0.0.2(1mo ago)15MITCPHP ^8.4

Since May 4Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/o0h/php-ext-astop)[ Packagist](https://packagist.org/packages/o0h/astop)[ RSS](/packages/o0h-astop/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

php-ext-astop
=============

[](#php-ext-astop)

A PHP extension that intercepts the compilation pipeline and prints the **AST** and **opcodes** for every file or string compiled during a request.

> **Note:** This project is a personal learning exercise to explore PHP internals — the compiler pipeline, AST structure, and opcode generation. It is not intended for production use.

---

What it does
------------

[](#what-it-does)

When loaded, `astop` hooks into three PHP internals:

HookWhat it captures`zend_ast_process`AST produced after parsing`zend_compile_file`Opcodes for each compiled file`zend_compile_string`Opcodes for `eval()` / `assert()` stringsAn optional **no-exec mode** (`ASTOP_MODE=no_exec`) also replaces `zend_execute_ex` with a no-op, so you can inspect compilation output without actually running the code.

---

Docker
------

[](#docker)

The easiest way to try it out — no PHP dev headers needed locally.

```
docker build -t astop .
```

Run an inline snippet:

```
docker run --rm astop -r 'echo "hello";'
```

Run a local file:

```
docker run --rm -v "$(pwd):/work" astop /work/your_script.php
```

no\_exec mode (dump only, skip execution):

```
docker run --rm -e ASTOP_MODE=no_exec -v "$(pwd):/work" astop /work/your_script.php
```

---

Install via PIE
---------------

[](#install-via-pie)

[PIE](https://github.com/php/pie) is the official PHP extension installer.

```
pie install o0h/astop
```

Build from source
-----------------

[](#build-from-source)

```
phpize
./configure
make
```

The extension will be built at `modules/astop.so`.

---

Usage
-----

[](#usage)

### Basic — dump AST and opcodes, then run the script

[](#basic--dump-ast-and-opcodes-then-run-the-script)

```
php -d extension=modules/astop.so your_script.php
```

### no\_exec — dump only, skip execution

[](#no_exec--dump-only-skip-execution)

```
ASTOP_MODE=no_exec php -d extension=modules/astop.so your_script.php
```

---

Example
-------

[](#example)

```
