2

I want my console program simply be run using Phalanger. I did not use IIS or .net in any way. Is it possible to use Phalanger in the same way that we use php.exe -f hello.php? How to compile and run following script using Phalanger.

<?php 
 echo "Hello World from Phalanger!";
Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
  • Compiling PHP? Are you sure you have picked the right language for your task? See also: http://stackoverflow.com/questions/1408417/can-you-compile-php-code – feeela Sep 17 '13 at 12:27
  • This seems like the kind of question best answered by reading the first chapter of the Phalanger documentation. What have you tried, and how did it fail? –  Sep 17 '13 at 14:54
  • @delnan It seems the manual only used IIS to run php codes. – Handsome Nerd Sep 18 '13 at 05:12
  • Here is the basic info about console applications in Phalanger http://wiki.php-compiler.net/Console_application http://wiki.php-compiler.net/Phpc.exe Phalanger compiles using phpc.exe utility. Specify /target:exe parameter to build executable file. List any reference to .NET or extension library by adding "/r:..." parameter. – Jakub Míšek Sep 18 '13 at 14:04

1 Answers1

5

Phalanger works as a compiler and runtime for PHP.

The easiest way is to install Phalanger Tools for Visual Studio, which allows you to create, build and debug console application.

Anyway, without Visual Studio; first you have to compile the code

phpc  hello.php /out:hello.exe

Optionally, if you have more files in your project, you should list them all, and specify the entering script file

phpc.exe /target.exe /entrypoint:hello.php /root:. /recurse:true /out:hello.exe

Which compiles everything (*.php) in current directory and subdirectories, and specifies "hello.php" to be the entering script file.

This creates an executable file "hello.exe".

After you succeed with this basic example, you may be interested in using some PHP extensions (like GD2). This can be done by adding following parameter, "/r:PhpNetGd2, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2771987119c16a03 which is the full name of the library containing GD2 functionality.

Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
Jakub Míšek
  • 1,036
  • 9
  • 12
  • Thanks for the answer. Placing such hello word example in Phalanger homepage can be very useful for those new to Phalanger. PHP programmer are reluctant to install VS before they see that Phalanger really works. – Handsome Nerd Sep 22 '13 at 07:14