PHP on .NET Core 3.0

Our recent work on the PeachPie compiler gives us a few cool abilities and features. Not only can you compile and run PHP code natively on the .NET runtime (which means all the performance benefits and interop with C#) but now it all works fluently on the new .NET Core 3.0 and ASP.NET Core 3.0. Let’s take a look at the new features and what had to be changed in order to take advantage of .NET 3.0.

How to get PHP on .NET Core 3.0 you say? First you need PeachPie, at least version 0.9.42. And in fact, you don’t have to download it at all, it gets downloaded by dotnet the first time you use it. Take a look at the Getting Started page for more details.

Why 0.9.42

The compiler already generates netstandard2.0 compliant DLL files, which are compatible with .NET Core 3.0, so why would you have to update the compiler? In short: there was a bug. We had emitted a .call instruction instead of .callvirt in case of abstract method calls. The .NET Core 2.0 runtime didn’t care much and silently changed it to the proper one, but .NET Core 3.0 throws a BadImageFormatException instead. Also, in our ASP.NET Core integration, we now force the synchronous IO since PHP’s echo is still translated into synchronous System.IO.Stream.Write and the new ASP.NET Core 3.0 only allows asynchronous IO by default.

What are the benefits

It’s all about performance. By switching your PHP app from .NET Core 2.0 to 3.0, you’ll get at least a +10% performance gain out of the box. Note that there are a lot of possibilities for further performance improvements and memory usage optimizations … we’ll be happy to write more about it once it happens.

But there is more in 0.9.42.

  • The new version implements more of the standard PHP library.
  • The database extension has been updated to the latest MySQL servers.
  • There are few fixes as well 

Moreover, a nice feature for C# interop – wherever in your PHP code you use the PHPDoc tag @obsolete , the compiler annotates the method or class with [ObsoleteAttribute] metadata. This has a nice consequence. Wherever you use an obsolete PHP function either in C# or the PHP code, you’ll get warned by the corresponding compiler (C# compiler or PeachPie compiler).

Any future work?

We are getting closer to the 1.0.0 version. A few more bugs have to be fixed, a few workarounds to be made; but most importantly the platform is becoming more stable and a native citizen in the .NET Core family. One of the cool features we’re planning to do is the async echo, which will improve the web server’s throughput.

A bunch of work will of course continue to be done on performance. Just by going through our code, we are aware of dozens of possibilities to optimize and do things more efficiently. Furthermore, we are working on a few more tools to increase the user-friendliness of the PeachPie platform. Stay tuned for more announcements on this.

Share this article:Share on FacebookShare on VKPin on PinterestShare on Google+Tweet about this on TwitterShare on LinkedInShare on Reddit
Posted on May 28, 2019, in category Announcement, News, tags: , , ,