Phalanger is a php language compiler and is also targeted. NET PHP runtime. It can be used to compile PHP Web projects into. NET bytecode and execute it in Windows using IIS or using mono and Apache as ASP.net applications on Linux. However, Phalanger not only compiles existing PHP applications into. NET.
We can use Phalanger to create a combination of. NET and PHP solutions in a way that is not possible with a standard PHP interpreter. With Phalanger extensions, PHP programs can be used directly. NET class, and. NET programs, such as those written in C #, can also invoke PHP scripts dynamically, or use functions and class "6" implemented in PHP.
In this article, I'll briefly introduce Phalanger and then look at three usage scenarios. We'll discuss how to consolidate PHP applications and. NET, how to run PHP applications efficiently on Windows, and how to use PHP as the ASP.net view engine.
Phalanger Introduction
Phalanger has been around for some time. The first edition of Phalanger was created in 2003 at Charles University in Prague as a software project. The development of version 2.0 was started later and released as an Open-source project in CodePlex in 2006. Microsoft supported the project for some time, and later a Phalanger developer joined Microsoft and worked on the dynamic language runtime.
Phalanger related activities resumed in 2008, thanks to the collaboration with Jadu, which uses Phalanger to build a. NET version of the CMS developed in PHP. Since 2010, the development of Phalanger has been funded mainly by Devsense, and it has also provided commercial support for Phalanger. The recently released version Phalanger 2.1 "7", which promotes compatibility with standard PHP implementations, leverages the DLR during the implementation of dynamic operations, and provides interoperability between PHP and other. NET languages such as C #, F #, and Visual Basic.
Components of Phalanger
Phalanger consists of several separate components that you can use to develop and run in. NET on the PHP application and use it. NET or mono to run them:
The Phalanger compiler Phalanger compiles the PHP source code into a. NET assembly, which can be executed using the. NET JIT (Just-in-time compiler, which generates local code for the current platform). The compiled PHP code uses the Phalanger runtime and the dynamic language runtime to provide a highly efficient implementation of the PHP language dynamic features.
Phalanger Runtime and Class library Phalanger runtime provides an implementation of PHP features such as arrays. Phalanger also includes for I/O, regular expressions, and other standard PHP library classes. NET implementation.
Locally extended on a 32-bit Windows platform, Phalanger can use all existing PHP 4 extensions through a local bridging program. Although this brings some run-time load, it allows us to run some PHP applications without the need for extra work.
Managed Extensions are packaged through. NET, PHP extensions can also be implemented again. These extensions can be made by any. NET language, and provides good performance. The Phalanger contains multiple extensions, including SPL, JSON, SimpleXML, MySQL, and MS SQL providers. The Devsense "9" also provides additional extensions, such as memcached, images, and curl.
The integrated Phalanger with Visual Studio is also integrated with Visual Studio (the most recent update supports Visual Studio 2010). The integration feature adds color highlighting and smart hints for PHP files, allowing us to debug PHP applications that run using Phalanger.
Phalanger use case
Phalanger is largely compatible with PHP 5 and can run a large number of open source PHP projects, including WordPress and MediaWiki. We can use it to integrate these projects into the. NET ecosystem or to develop new projects that will have the advantages of PHP and. Net. For the remainder of this article, we will discuss the following three usage cases:
Scenario 1: Run the PHP application efficiently. The performance of PHP applications compiled with Phalanger on Windows is higher than using the standard PHP interpreter through fastcgi. This makes it tempting to choose Phalanger to deploy PHP in a Windows environment.
Scenario 2: Integrate WordPress with asp.net. PHP code compiled with Phalanger can call all. NET libraries. This can be used to share user databases or other data between PHP and ASP.net applications.
Scenario 3: Invoke PHP from the asp.net application. PHP's flexibility is useful for scripting or writing the presentation layer of a Web application. With Phalanger, we can be in. NET and use PHP as the scripting language or view engine.
The following three sections discuss various scenarios in detail. We'll start with an overview and then look at some technical details that will show you what's interesting in Phalanger.
Scenario 1: Run PHP applications efficiently
Phalanger is able to run PHP applications efficiently because of the following two reasons. First, it compiles the PHP source code rather than interprets it, and second, it runs the application as a asp.net application, which provides additional performance benefits under Windows.
compiling PHP using Phalanger and. Net
The compilation process is shown in Figure 1. As shown on the diagram, Phalanger compiles the PHP source code into a. NET IL (intermediate language), which is a low-level byte code that is independent of the schema. The compiled code uses the PHP core library (part of Phalanger) and the Dynamic Language runtime (DLR) to perform standard PHP operations. When the application starts, the. NET JIT (just-in-time) compiler converts these components into native code optimized for the current processor architecture.
Figure 1. The process of compiling the PHP source code with cost code using Phalanger
As the Phalanger review shows "10", WordPress, compiled with Phalanger, is better at windows than using a standard PHP interpreter through fashcgi, and a little better than using PHP via Wincache. However, the evaluation did not test the latest version of Phalanger, which was further optimized using the DLR.