Pyhp
PyHP is an implementation of the PHP language with JIT support using the RPython technology.
Install / Use
/learn @juokaz/PyhpREADME
PyHP
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.
Features
- 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!

Project structure
main.py- main entry pointsourceparcer.py- parses a given PHP file using thegrammar.txtdefinition, and produces an AST tree consisting ofoperations.pynodesbytecode.py- turns the AST tree produced bysourceparcer.pyinto bytecode by callingcompile()on the tree. Produces aByteCodeinstance consisting ofopcodes.pynodesframe.py- execution frame. Contains the stack and the variables/functions map for the function or the global program. A frame instance is passed toexecutemethod of aInterpreterinstance as the only parameterinterpreter.py- loops over a list of bytecodes and evaluates aopcodes.pyhandlergrammar.txt- EBNF PHP grammar used bysourceparcer.py
Additional files:
operations.py- AST tree nodesopcodes.py- class per each opcode. Each opcode has aeval(frame)method which gets called by theInterpreter.execute()methodsymbols.py- contains an optimizedMapclass used for symbols map inscopes.pystdlib.py- various PHP standard library methods likestrlendatatypes.py- all datatypes' box classes used to store the variables, like int, float, array, etc.
Building
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/logparser.py 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
Related Skills
openhue
353.3kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
353.3kElevenLabs text-to-speech with mac-style say UX.
weather
353.3kGet current weather and forecasts via wttr.in or Open-Meteo
casdoor
13.3kAn open-source AI-first Identity and Access Management (IAM) /AI MCP & agent gateway and auth server with web UI supporting OpenClaw, MCP, OAuth, OIDC, SAML, CAS, LDAP, SCIM, WebAuthn, TOTP, MFA, Face ID, Google Workspace, Azure AD
