tags:

views:

372

answers:

3

I am coding a web application in PHP and it has some performance intensive parts that I'd like to rewrite in a compiled language. I know that I could probably get this done more easily just by writing a C++ extension for PHP, but I'm a bit too spoiled by managed languages like C#, so I'd like to avoid C++ if possible.

If I wanted a PHP script to execute a function inside of a running C# (on mono) process, how could I do this? My first guess is to have PHP open a socket to the C# process, do the work, and close the socket, but I think that would add unnecessary overhead.

Are named pipes something that could solve this problem? If so, do they work on windows (my development machine), and how do I use them from C#?

If not, what other options do I have?

+7  A: 

Have you considered using the PHP.NET compiler, Phalanger?

James Hugard
+1: I read about a company that used this to convert several thousand php files and over 2 million lines of code into 3 .NET assemblies in .net magazine xD. Much more portable, and faster. There is now an almost 1-to-1 conversion match between php and C# and you can communicate between php and .NET
Callum Rogers
A: 

There was a PECL extension for mono, but it's no longer maintained (last version was in 2003) ; so, this one is probably bad idea on the long term...

For something more recent, searching the php's documentation, if you want to work with .NET, you might be interested by COM and .Net (Windows) ; but it probably won't be OK for you, as you specify "mono", which probably means "non-windows" platform :-(

Every time I've heard about extending PHP with a compiled langage, it was using C (and, sometimes, C++) ; I've never about using C#/.NET/mono for that...

... So, you might not find what you are looking for :-(

Like you said, with multi-processes, and communication between those, you could do something... But not sure it's such a good idea...

(Compiling PHP to .NET seems possible, though -- but it's like the exact opposite of what you're asking ^^ )

Pascal MARTIN
Actually, using Phalanger (PHP.NET) would allow C# or Managed-C++ to be called directly from PHP (and vice-versa), with almost no overhead.
James Hugard
Oh, that's good to know ; thanks for the info !
Pascal MARTIN
+1  A: 

Another option is to write a PHP module that embeds the Mono runtime in your application.

Here is the documentation on embedding the Mono runtime in your application, in this case, it would be PHP:

http://mono-project.com/Embedding_Mono

miguel.de.icaza