Compiler command-line options

Here we list command-line options that can be passed to the kphp command.

Options and environment variables

Specifying options looks like this:

kphp [options] main-file.php

Every option has a corresponding environment variable. If both an environment variable is set, and an option is passed, an option has higher priority.

KPHP_ENV_VARIABLE_1=... kphp main-file.php

All options are either boolean or parametrized. Boolean options are false by default and become true when passed (they don't accept any command-line parameter).

List of available compiler options

These are options for generating C++ code — NOT for a server. Server options are listed here

Show all available options and exit.
This documentation refers only important options, not absolutely all, so -h will show more than listed below.

Verbosity level, default 0.
Available levels: 0 | 1 | 2 | 3.

Path to KPHP source code. Some lookups will be done inside this folder, functions.txt for example.
When using Docker or .deb packages, it equals to /usr/share/vkontakte/kphp_source directory.
When compiling from sources, the default value of this argument is auto defined with CMake.

The output binary type, default server.
Available modes: server | cli. Use cli for CLI mode: just execute the script and exit.

Paths where PHP files will be searched, it can appear multiple times, default empty.
These directories are roots when require_once is used and where classes are searched by autoloading rules.

Destination folder: where C++ sources and the resulting binary will be placed, default '.' in Docker.

The resulting binary file name, default server | cli depending on --mode.

Do not compile/link a binary after C++ codegeneration, default 0. When 1, only the C++ code is generated.

Threads number for PHP → C++ codegeneration, default CPU cores * 2.

Processes number to C++ parallel compilation/linkage, default CPU cores.

A .tl file with TL schema, default empty.

All compile-time warnings will be treated as errors, default 0.

If passed, print all warnings to file, otherwise, they are printed to stderr, default empty.

Show all type infererring errors (if false, only the first error is shown), default 0.

Colorize warnings output: yes | no | auto, default auto.

If passed, save codegenerations metrics to file, default empty.

Specify the compiled PHP code version, default ‘unknown'.
It will be embedded to the resulting binary and can be accessed from it — with --version on launch or by querying server status.

C++ compiler for building the output binary, default g++.

Directory for c++ compiler toolchain. Will be passed to cxx via -B option.

Extra C++ compiler flags for building the output binary, default -O2 -ggdb + some others.

Extra linker flags for building the output binary, default -ggdb.

Use dynamic incremental linkage ld for building the output binary, default 0, meaning that KPHP_CXX is used.

Enable embedded profiler, default 0.
Available modes: 0 | 1 | 2. See the link above for details.

Enables get_global_vars_memory_stats() function and compiles debug code tracking memory, default 0.

Enable all inspections available for @kphp-analyze-performance for all reachable functions and generates a json report, default 0.

Forbid to use precompiled headers, default 0.

Forbid to use an index file which contains codegen hashes from previous compilation, default 0.

Show codegeneration progress, each step, line by line, default 0.

A folder that contains composer.json file and vendor/ folder, default empty.
If empty, KPHP won't search for Composer modules at all, so specify this option to enable psr-4 autoload.

Include autoload-dev section for the root Composer file, default 0.

Makes typing of functions mandatory, default 0. Navigate here for details.

Makes typing of classes mandatory, default 0. Navigate here for details.