PeachPie is an open source PHP compiler and runtime for .NET and .NET Core. We have covered the project about four years ago when it was work in progress, but today the project is member of the .NET foundation with a clear roadmap and continuous integration.
Current version 1.0 still in alpha provides PHP 7.4, related IDE support, user-friendly error messages, documentation, processing composer.json. The next major will support include of generated scripts, compile-time optimizations, runtime optimizations, dynamic support in C#, more C# interoperability features, correctness fixes, standardized API.
With PeachPie you can open the world of PHP to the .NET and vice versa. You can for example integrate wordpress into your .NET as a module. Compiling PHP projects into .NET bytecode in the same way as C# is compiled, make it like a new natural part of the .NET platform.
Today the project have an interesting marketplace where you can see example of PHP applications compiled to .NET like WordPress blogging platform, PHPGeo a simple Geolocation library, Randomlib the library for generating random numbers and strings of various strengths, and many others…
So today you can use any PHP library or project in your .NET application, however we didn’t find yet any use case of the “versa”.
Getting started with PHP .NET Compiler
You can install PeachPie as a VisualStudio extension from the marketplace, the extension adds project templates into your Visual Studio that makes it easy to start building your .NET powered web, library or application. Then you can navigate to the PHP project templates and choose the one you want to get started with.
Finally you can build your project and run it with F5. You can also get the Web or Console App command line tool. In this case you need to install the .NET Core SDK, then install Peachpie .NET Templates, finally you can create a website or a console PHP application using :
dotnet new -i Peachpie.Templates::*
dotnet new web -lang PHP # To create a website
dotnet new console -lang PHP # To create a console app
dotnet run # Compile your code and run it.
Features in the 1.0 release
The focus in this release was on open-source PHP projects, as well as some clients’ applications for version 1.0.0 and they essentially intended to get them running on .NET fluently. In addition, there were a few features that were necessary to implement so that the project would be practically usable :
PHP projects can be opened, built, debugged, and profiled in Visual Studio.
The latest WordPress version running on .NET, without any source files. This includes WordPress, the majority of plugins, e.g. Woocommerce and Elementor, and themes.
Selected composer packages compile and can be used as a class library by a C# project (Twig, PHPUnit, RandomLib, dependencies of the Laravel framework).
Code Analysis (compilation) provides detailed and useful diagnostics about the PHP code.
It’s interesting to have an overview on performance of applications built with PeachPie. The performance itself depends on how the application is written. Obviously, the compiler likes strongly typed declarations. Specifying type hints within the PHP code is still backward compatible with regular PHP and also it adds the benefit of a safer and faster runtime.
This have been said, you shouldn’t expect to get a huge performance improvement, however a benchmark using gitter.io chat have been done with the official Zend bench got a 27% performance improvement:
Overall the project got a real big boost compared to the last years, it’s no longer a proof of concept or a work in progress, but a structured project with CI tests and clear roadmap, in addition to many great showcases. If the project might not be really useful for PHP developers, it will certainly be a great help to the .NET community to profit from the tons of open source software available in PHP. Or maybe vice versa ?