PHP on .NET?


Originally posted in my old blog at My Opera

Microsoft's ASP.NET has a lot of useful features, things you might want to have in PHP too.
But you can't run PHP as a .NET language because Microsoft already has ASP.NET… or can you?

It appears that some Czech programmers came up with this idea few years ago and they made a PHP compiler for .NET, Phalanger, which compiles PHP code into MSIL which is understood by the .NET Framework.

There are some immediate advantages you can think of:

  • Better speed: because the code is compiled into MSIL and Just-In-Time compiled, it has better performance.
  • Access to the .NET library
  • You can use PHP software in an ASP.NET website – there are many great PHP applications

PHP ran with Phalanger is almost twice as fast as running it with the native Zend Engine. According to Code Project's Phalanger benchmarks, it serves phpBB pages twice as fast as “native” PHP!

the .NET Library:
The .NET Framework library is huge, it's even larger than the amoun of functions bundled in with PHP, and you get all that and the functions from PHP too.

PHP software:
Phalanger runs many of the big PHP projects, such as the mentioned phpBB which is a very popular forum software.

There are some drawbacks from using the .NET, though…
You will have less hosting options as there are way more PHP hosts than .NET hosts. Phalanger runs on Mono too, but I haven't ever seen a hosting provider which gives you Mono, so you probably are limited to Windows-hosting only.

They have some Visual Studio integration done as well, but they are still working on IntelliSense support, so if you're really used to that it might feel weird to not have it.

All in all, it's something worth checking out. Just the fact that PHP runs faster with it sounds good. I don't have access to a Windows server though, and I had problems getting mod_mono running on my Debian box, so we'll have to see if I can get it working at all.