PyHP is an implementation of the PHP language with JIT support using the RPython technology.
Python PHP Makefile
Switch branches/tags
Nothing to show
Clone or download
Latest commit 5615806 May 29, 2016


PyHP is an (incomplete!) implementation of the PHP language using the RPython technology. It uses JIT transformer provided by the RPython library to achieve good performance.

PyHP stands for Python + PHP.

HippyVM is too built on top of RPython, and is a complete, working implementation.


  • all variable types like int, float, string, array, iterator
  • if, while, for, foreach statements
  • functions
  • pass by value or by reference to a function
  • global variables in function blocks using global
  • global constants using define()
  • (incomplete) standard library functions
  • unicode support for function/variable names and string values. PHP 6 compatible!

PHP 7 vs PyHP

Project structure

  • - main entry point
  • - parses a given PHP file using the grammar.txt definition, and produces an AST tree consisting of nodes
  • - turns the AST tree produced by into bytecode by calling compile() on the tree. Produces a ByteCode instance consisting of nodes
  • - execution frame. Contains the stack and the variables/functions map for the function or the global program. A frame instance is passed to execute method of a Interpreter instance as the only parameter
  • - loops over a list of bytecodes and evaluates a handler
  • grammar.txt - EBNF PHP grammar used by

Additional files:

  • - AST tree nodes
  • - class per each opcode. Each opcode has a eval(frame) method which gets called by the Interpreter.execute() method
  • - contains an optimized Map class used for symbols map in
  • - various PHP standard library methods like strlen
  • - all datatypes' box classes used to store the variables, like int, float, array, etc.


Build the container first

docker build -t juokaz/pyhp .

or pull from docker hup

docker pull juokaz/pyhp

Building the interpreter

make build

Or to build without JIT support

make build-nojit

Running the benchmark

make bench

Or run any PHP file

./build/pyhp bench.php

Starting the web server

./build/pyhp --server 8080

Accessible through http://localhost:8080/bench.php.

Printing the bytecode

./build/pyhp --bytecode bench.php

Printing the AST tree

./build/pyhp --ast bench.php

Debugging the interpreter

PYPYLOG=jit-log-opt:jit.txt ./build/pyhp bench.php

Plot the trace as a graph

PYTHONPATH=$PYTHONPATH:/home/vagrant/pypy-src/ python ~/pypy-src/rpython/tool/ draw-time jit.txt --mainwidth=8000 filename.png

Running the tests

make tests

Or to run with coverage information

make tests-cov

Building the docker container

docker build -t juokaz/pyhp .

Attributions and inspirations

JavaScript on top of RPython

Example interpreter

Pascal on top of RPython

HippyVM - php on top of RPython