1

I have a C# application that needs to call a PHP script, and get the output, in the fastest possible way. The options I explored:

  • Executing the script with PHP CLI (Pro: Easy / Cons: No Opcode Cache / Precompilation ]
  • Compiling the PHP (Phalanger, Hiphop, etc.) [Pro: No Webserver / Con: Compatibility ]
  • Using an embedded webserver (AppWeb, Cherokee, Lighttpd) [Pro: Simple / Cons: Deployment ]

Are there any other options left?

EDIT: The best possible option would be to make use of the build-in FastCGI server of PHP, by running php-cgi.exe -b 127.0.0.1. But there seems no (C#) code to talk to a server available. While there are so many server-side libraries (like FCGIDotNet and SharpCGI), they all implement the server-side of the protocol.

11
  • 4
    What does the script do? Commented Jun 9, 2011 at 14:48
  • 1
    Any requirements discussion must involve, first and foremost, what the solution must do. Yet, here, you don't even mention it. Commented Jun 9, 2011 at 14:49
  • 1
    @Fase: ... which is a packaged webserver. Relevance? Commented Jun 9, 2011 at 14:50
  • 1
    Why is executing PHP in the CLI very slow? And why can't C# just do the job? Commented Jun 9, 2011 at 14:50
  • 2
    @thephpdeveloper Executing PHP on a file containing <?php ?> via CLI here is essentially instantaneous. Commented Jun 9, 2011 at 14:52

2 Answers 2

2

One other option could be to run the PHP CLI script as a daemon (good blog post on this here).

If the script has a particularly long startup/cleanup, then running it as a daemon would mean that you only do this once.

The downside is that you'd need to write a way of communicating with that daemon, to get the data from C# to it. You'd also need to keep an eye out on its memory usage over time.

The best method is always going to be specific to your script though.

Sign up to request clarification or add additional context in comments.

1 Comment

Looks very interesting! The problem is that CLI is the slowest on Windows, and the script is for Linux. Since my app is crossplatform, I still need a Windows-solution, but very good answer.
0

As you may know, PHP originally stood for "Personal Home Page", it is now said to stand for "PHP: Hypertext Preprocessor", which literally states it's usage, and basically is not something that a developer would embed into his application just to have a scripting option.

Unless you have some really specific piece of software and strong arguments, I'd suggest you to stick to Lua, or similar scripting libraries which are easy to embed and maintain. Otherwise, use it the way as everyone is using it, CLI. Or else be prepared to face the consequences.

1 Comment

Im trying to re-use an existing library, so I have no choice for other languages, except for rewriting the whole library from scratch.

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.