Depends of course on what kind of data you want to exchange, if the applications are on the same server or on two different ones etc.

I did briding between PHP and C# in some of my web based projects. What I did: create an ASP.NET MVC project which exposes a RESTful API. The methods exposed by this API are then called from PHP via HTTP (using CURL). I used JSON as a data exchange format to pass data from PHP to C# and back again. This worked good as the two applications were on different servers.

I could also imagine some kind of socket server. E. g. a background process written in C# is listening on some port, and then you connect to it via PHP´s socket functions. I did something like this to connect PHP and Java. The Java app ran as a demon process on port XXXX and was a wrapper around Apache FOP. I used PHPs socket functions to pass XML and XSLT to the Java demon which then used Apache FOP to transform the data into a pdf and returned that via the socket connection back to PHP which in turn sent the PDF file to the client requesting the page.

There are probably some other approaches, but these were my experiences so far in connecting two different technologies together.

EDIT: as an aside: PHP on a windows webserver using IIS was really not that nice to work with. Sometimes strange errors occured or certain permission related errors that were not easy to resolve. YMMV though.

C# + PHP in the same application?
I am trying to create a circuit which will allow me to scale and offset a voltage (be it AC or DC) to within the range of the Arduino ADC.

The voltage could be anything between + and - 250V, but I also need to have good sensitivity over lower voltage ranges too.

To this end I am looking at a circuit whereby you can vary the voltage range that it expects the input to be and amplify/attenuate it accordingly.  How I will be making the decision and setting the different gains is for another topic for now.  I am only interested in the scaling and offsetting at the moment.

So far I have come up with this circuit:



Which appears to do just what I want for the +/- 250V range.  I don't know how "safe" this circuit is, and if I am endangering any of the components with the 250V or not.  The graphs at the bottom are (left to right) the input voltage, the power consumption of the bottom 10M resistor, the voltage across the 100M resistor (which is simulating the Arduino ADC input) and the power consumption of the upper 10M resistor.

Now, if I drop the input voltage to just +/- 2.5V and tweak the op-amp feedback resistor accordingly, for some reason the offset voltage the op-amp is adding jumps right up.  I don't know for sure if this is the fault of the simulator I am using, or if it is really what will happen, as I haven't yet breadboarded this circuit (I guess that's the next stage).

This is the output from the 2.5V version:



You can see how the offset has jumped up and the output is clipping massively.

If I drop the lower 10K resistor to the virtual ground offset voltage divider to just 3.3K it compensates, but that's not nice - I would like to just vary the one resistor.  

The op-amp is (will be) a 5V single supply rail-to-rail I/O one.

The two diodes are to protect the input of the op-amp against over voltage - I don't know if this circuit strictly needs them, but I guess it doesn't hurt to have them there.

Also, I don't know if the resistor values are quite what I want - I chose them to keep the power consumption right down and the impedance right up.  I don't want them to impact the frequency response of the circuit more than I can help - the input waveform could be anything from DC up to around 500KHz or so, and I need that reproducing at the ADC end as faithfully as I can.  (I know the Arduino can only really sample at lower speeds than that, but the Arduino is just for experimenting - the final system will use a dsPIC with 1.1Msps ADC).

So, what can I do to A) get a more stable offset, B) allow the varying of the input sensitivity without nuking either the op-amp or the ADC, and C) make the circuit safe to connect to, for example, a European mains voltage?
