3

I would like to give my users the ability to configure some php script to interact with my applycation.

I would like to give the user a Memo. The user writes some code with a php syntax, then press execute. The php engine executes the code, so I can print a result.

For example I would like to write something like:

PHPassembly = Assembly.LoadFrom("php5ts.dll"); 
ExecutePHPScript(PHPassembly,StringContainingAScript);
ResultVar=GetPHPVar(PHPassembly,"ResultVar");

I don't have a web server. I don't have an internet connection. Only a local application for windows.

I have tryed to load the php5ts.dll, but the compiler says that I need an assembly manifest.

Someone knows how to interact with php?

2
  • Would executing something on the command line be an option? I don't think you can use PHP directly in managed code - at least I don't know of any project that tries to make that possible. Commented May 19, 2011 at 14:09
  • @Stefan Gehrig: Command line is not an option. For example I would like to be like Apache (I don't want to use Apache). When I was developing with Delphi I used this kind of technique. Commented May 19, 2011 at 14:47

4 Answers 4

2

You need 2 files (from php-5.3.5-Win32-VC9-x86) php-win.exe and php5ts.dll
Than just place those 2 files in you executable directory and run:

string code = "echo 'test';";

System.Diagnostics.Process ProcessObj = new System.Diagnostics.Process();
ProcessObj.StartInfo.FileName = "php-win.exe";
ProcessObj.StartInfo.Arguments = String.Format("-r \"{0}\"", code);
ProcessObj.StartInfo.UseShellExecute = false;
ProcessObj.StartInfo.CreateNoWindow = true;
ProcessObj.StartInfo.RedirectStandardOutput = true;
ProcessObj.Start();
ProcessObj.WaitForExit();
string Result = ProcessObj.StandardOutput.ReadToEnd();
MessageBox.Show(Result);
Sign up to request clarification or add additional context in comments.

5 Comments

a pretty good solution, but not so convenient: I have to create a process each time. It's like using it via command line: not a real integration.
how do you image doing it else way? Just Create a process with all parameters outside executing code, and just change arguments every time you execute code
It doesn't matter if u run code with -r (code) or -F (file), u have to start php to retrieve result. "Same thing" does Apache but in background ;)
really? Does Apache run a separate php instance for each php request? I don't think so: I have never seen the process "php-win.exe".
When php is run as CGI apache creates process for each request, when run as module, there is one process executed with every request (almost same as i proposed). Same thing would be with running php without apache, but with nginx, you would have to create process with every request.
0

You can try hosting the php runtime locally. There are preconfigured packages for that, with PHP + Apache, like xampp and WampServer. This way, you can call it via HTTP requests to localhost (such an approach is discussed here).

4 Comments

No web server. No other application running. Only dll link or similar.
Well, then there's Phalanger (php-compiler.net), which allows one to compile PHP into .NET, but I don't know if it could be used to solve your problem. EDIT: You could also try installing just PHP, without a webserver, and invoking the scripts via CLI.
Phalanger is a php compiler. I want to integrate php engine in my applications.
I know. The suggestion was to integrate by means of turning the user's php script into a .net assembly, and calling it through "normal" means...
0

With a bit of configuration,you could execute your code against php running on the command line.

See php.net for more info

1 Comment

a pretty good solution, but not so convenient: I have to create a shell process each time. Not a real integration.
-1

in search of something similar myself I found this question.

maybe port and include code from http://ph7.symisc.net/index.html if you don't need too fancy php stuff?

1 Comment

this hardly answers the question, so it should not be posted as an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.