FAQ

This section contains helpful notes and brief answers to common questions about KPHP.

If you have something to ask besides these topics, use GitHub issues or a Telegram chat.


Is KPHP faster than PHP? To what extent?

Typically, KPHP is 3–10 times faster, especially if you focus on clean types.
Read more in-depth information about this on the benchmarks page.

If KPHP is a compiler, how does it serve HTTP requests?

Generated C++ code in coupled with a web server, but you can also launch your script in CLI mode.

PHP 7 introduced type hints, isn't that enough?

With PHP 7 type hints, you can use primitives and ?nullables, but you can't express T|false or int[].
With PHP 8 union types, you can use int|false, but you still can't express int[] or (int|false)[]|false.

KPHP type system is much more expansive: besides primitives and typed arrays, it contains tuples, shapes, and others. They can't be expressed by PHP syntax and should be written as PHPDoc only.

Does IDE understand KPHP extended types?

KPHPStorm is a PhpStorm plugin, that makes IDE understand extended PHPDoc and highlight mismatch types on the fly, all without compilation.

Is there something like "duck typing", regardless of strict typing?

For this, you might want to read about generic functions.

Why can't KPHP compile my code?

That's because KPHP can't compile just any random PHP code. Your code must follow strict guidelines.
Take a look at the information on this page.

Why doesn't KPHP support Postgres and all other DBs?

KPHP was initially developed at VK, which uses self-written storage engines that are not made open source yet.
That's why KPHP has great support for TL/RPC, but almost nothing for “real-world” DBs.

Will Postgres and other DBs be supported in the future?

Probably. They can be added, but the main obstacle is in making them async.

Are PHP extensions compatible with KPHP?

No. Zend API has no relation to internal KPHP runtime.

How to use PHPUnit with KPHP?

Don't use it in production. Test your site on PHP, and then compile a binary without dev tools.
Read more in the dedicated article.

Is there a "list of libraries" compatible with KPHP?

Consult this repository containing PHP snippets which you can copy and paste. Something more sophisticated might be added in the future.

Where do I find logs and runtime errors?

KPHP is a server, and it writes a lot of logs and statistics.
When a runtime error occurs, a C++ trace is logged. To map this trace onto PHP code, you'll need special magic.

Does KPHP compile the whole project from scratch every time?

KPHP is incremental. It does not recompile C++ sources that haven't changed since the previous run.
KPHP parses all reachable .php files on every run. Without parsing everything, type inferring is impossible. But it rewrites and invokes g++ only on files that were changed by themselves or through dependencies. This is especially useful in huge projects where compiling C++ code takes a long time.

Who uses KPHP except for VK.com?

As of the first public release? Nobody. Standard database support needs to be added to greatly improve potential KPHP applicability.

Сan you say a few words about KPHP internals?

Here is a separate section about KPHP architecture, not just a few words :)