Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can PHP talk to a C# process running on mono?

Tags:

c#

php

mono

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?

like image 701
ryeguy Avatar asked Jul 21 '09 20:07

ryeguy


People also ask

How do I communicate between C++ and PHP?

1) To take something from C++ app PHP connects to that app using stream_socket_client function. C++ app is listening on host and port using socket , bind and listen functions. As soon as connection arrives C++ app accept it and then in a separate std::thread serves it ( recv to get request, send to send response).


2 Answers

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

  • Runs some very well-known PHP applications, including:
    • MediaWiki
    • PhpMyAdmin
    • PhpBB 2 & 3
  • Works under Mono
  • Performs substantially better than PHP 4.3.7 on Apache (PDF: see benchmark at end)
  • Call .NET libraries (including your own) from PHP (PDF)
  • Call PHP from other .NET languages
  • PHP/CLR Language Extensions (PDF) make it a First Class .NET Language
like image 74
James Hugard Avatar answered Oct 08 '22 01:10

James Hugard


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

like image 29
miguel.de.icaza Avatar answered Oct 08 '22 02:10

miguel.de.icaza