Hello Phalanger Let us write a simple Hello Phalanger web page. Type in the following code in a text editor (like Notepad):
print(“Hello Phalanger”); ?>
Save the above file as hello.php in c:\inetpub\wwwroot. Browse to the web page at http://localhost/hello.php and you will be greeted by a “Hello Phalanger” message. Note that we did not install PHP (from www.php.net) or PHP ISAPI DLL or PHP CGI. Phalanger has taken over as the scripting engine for .php files. It compiles and displays the output of the PHP code.
With the Phalanger extension for Visual Studio, you can write the above mentioned Phalanger page in Visual Studio. Now we need to start Visual Studio 2008. For this, click on File->New Website. Select PHP from the language dropdown and then select Phalanger PHP Web. This will open a new Visual Studio project which will include a file named default.php. Type in the above print( ) statement in default.php.
Right click on the Website in the Solution Explorer and select “View in browser”. This will launch Visual Studio's built in web server and will show a page with the files. Click on default.php to see the output.
Debugging Phalanger apps in Visual Studio Before you debug Phalanger apps, you need to take care of the following. In the debug mode, Visual Studio does not show the runtime values of PHP variables on mouse over. Instead you will need to use the Locals window.
To inspect the runtime values of PHP variables, you will need to launch the Locals window, while in debug mode, via Debug>Windows>Locals. In this window, you can spot the local (to a function) variables. To look at global variables, expand the tree and you will see the runtime values of the global PHP variables under Global Variables.
PHP Assembly in C# applications After the Hello Phalanger program, lets look at something more interesting. What if one can write assemblies (or class libraries) in PHP which in turn can be used in .Net applications (Web or Desktop)? This will prove useful if you have an existing investment done in a complicated logic written in PHP and now want to use the same logic in a .Net application.
As a simple example, we write a PHP class library named Cryto which has a function/method called GetMD5(). This function simply accepts a string, uses PHP's inbuilt MD5 function and returns the MD5 hash of the string.
In Visual Studio, click on File>New Project. Under the “Project Types” menu, select Phalanger. From the right pane, select Phalanger Class Library. For the project name, type in Crypto and then click on Ok button. Now go to the the Solutions Explorer and here click on the Library.php, which will look like this:
class Library { function __construct() { } }
You need to modify the code to the following:
[Export]class Crypto { function __construct() { } function GetMD5($str) { return md5($str); } } ?>
Now build the project and create a new .Net Web application in C#. Right click on the Project and click on Add Reference. Then browse to the assembly file (Crypto.dll) of Crypto. The assembly file can be found, typically, in My Documents\Visual Studio 2008\Projects\Crypto\Crypto\bin\Debug. You will also need to add a reference to PhpNetCore.dll (found in Program Files\Phalanger\Bin directory).
Now in the code behind (Default.aspx.cs, for example), you can call the the GetMD5() function, of the assembly written in PHP. This can be done as shown below:
Crypto crypto = new Crypto(); string str = (string)crypto.GetMD5("Hello Phalanger"); Response.Write(str);
To explore more about Phalanger plug-in, browse to the site http://php-compiler.net/doku.php and learn more about other nifty uses that you can put this software for.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.