Page 1 of 1

running on custom webserver

PostPosted: January 20th, 2014, 10:22 am
by kaiwachter
HI Guys,
i am new to phalanger but it sounds absolutely interesting.
We have developed a huge application runnning on a custom webserver (not IIS or Apache). it is 100% .Net).
One case is to host Webpages. we have integrated PHP by FAST CGI currently.
How can i run Web applications build in PHP with phalanger instead of PHP.
Is there a way to run the PHP files like call php.exe?
Any code sample is appreciated.

best regards
Kai

Re: running on custom webserver

PostPosted: January 20th, 2014, 2:46 pm
by Jakub Misek
Hi,

Phalanger has built-in request handler which caches/compiles/runs PHP file requested by web server;

In IIS the configuration is following:
Code: Select all
<system.webServer>
    <handlers>
      <add name="PhalangerHandler" path="*.php" verb="*" type="PHP.Core.RequestHandler, PhpNetCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=0a8e8c4c76728c71" resourceType="Unspecified" preCondition="integratedMode" />
    </handlers>
  </system.webServer>


You can reuse/call this handler in order to process web request.

To run php script file from command line, you have to first compile it
Code: Select all
phpc.exe /target:exe file.php
and then run it
Code: Select all
file.exe

Re: running on custom webserver

PostPosted: January 20th, 2014, 3:06 pm
by kaiwachter
wow thats cool.
do you Need to set all the PHP variables also as Environment variables like we do that for the phpcgi file?

something like:

Code: Select all
            Process process = new Process();

            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.FileName = "index.exe";
            process.StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
            var variables = CgiHelper.GetEnvironmentVariables(irequest, path, scriptName);

            foreach (var item in variables)
            {
               process.StartInfo.EnvironmentVariables.Add(item.Key, item.Value);
            }
  // Start the process
            process.Start();


best regards
Kai

Re: running on custom webserver

PostPosted: January 23rd, 2014, 11:18 am
by Jakub Misek
when running web server, you don't want to run the .exe for every request (in case of .NET it would make huge overhead)

Please take a look on PHP.Core.RequestHandler class. You can reproduce steps done there. The only catch is, it makes use of System.Web.HttpContext and most of variables and states are filled from it. Including session handling and other web-related routines.

If you would like to use Phalanger in the context of your custom web server, without valid HttpContext instance, you might lose some features. (some functions rely on this class, checks HttpContext.Current etc.)

Re: running on custom webserver

PostPosted: January 23rd, 2014, 11:20 am
by Jakub Misek
Variables are initialized on every request in PHP.Core.AutoGlobals, method Initialize. They come from System.Environment.GetEnvironmentVariables(), HttpContext.Request.ServerVariables, Request.QueryString, Request.Cookies