Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know it's a really hacky solution, but if you need a bit of PHP code that you don't want to have to repeatedly port to C# each time, you could try the following approach, although it means that you would need the php command line tool on the target machine.</p> <p>First step is to have a php script that continously reads data off stdin, decodes it using this special class from the vendor, and writes the result out to stdout. Really simple example:</p> <pre><code>&lt;?php include("VendorDecodingClass.php"); while(true) { $input = fgets(STDIN); //read off of the stdin stream //can't remember if this is valid, but somehow check that there is some data if($input) { //pass it off to the vendor decoding class $output = VendorDecoding::decode($input); fwrite(STDOUT, $output); //write the results back out } //sleep here so you don't suck up CPU like crazy //(1 second may be a bit long tho, may want usleep) //Edit: From Tom Haigh, fgets will block, so the sleep isn't necessary //sleep(1); } ?&gt; </code></pre> <p>Anyway, once you have that in place, in your C# application, right at the start, create a new Process to run that script and then save the Process instance somewhere, so you can reference the STDIN and STDOUT at a later point. Example:</p> <pre><code>ProcessStartInfo procStartInfo = new ProcessStartInfo("php", "yourscript.php"); procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; procStartInfo.CreateNoWindow = true; Process proc = new Process(); //store this variable somewhere proc.StartInfo = procStartInfo; proc.Start(); </code></pre> <p>Then, when you want to decode your data, you just write to the stdin of the php process you created, and wait for a response on the stdout. Using the stdin/stdout approach is a lot more efficient than creating a new process each time you want to decode some data, because the overhead of creating that process can be noticeable.</p> <pre><code>proc.StandardInput.WriteLine(somedata); //somedata is whatever you want to decode //may need to wait here, or perhaps catch an exception on the next line? String result = proc.StandardOutput.ReadLine(); //now result should contain the result of the decoding process </code></pre> <p>Disclaimer here, I haven't tested any of this code, but that is the general gist of how I might do it. </p> <p>Something else I just thought of, you will want some mechanism for terminating that PHP process. It may be OK to use <code>Process.Kill</code>, but if the decoding does any file IO, or anything critical you may want to send an interrupt signal to the php script somehow.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload