Eğer php komutu gerekir demektir rağmen, ben bu gerçekten hacky çözüm biliyorum, ama sen C # her zaman tekrar tekrar bağlantı noktasına sahip istemiyorum PHP kod biraz gerekiyorsa, aşağıdaki yaklaşım deneyebilirsiniz hedef makinede satırı aracı.
İlk adım sürekli, stdin kapalı verileri okur satıcıdan bu özel sınıf kullanarak çözer ve stdout dışarı sonucu yazar bir php komut dosyası sahip olmaktır. Gerçekten basit bir örnek:
<?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);
}
?>
Neyse, size bir sonraki noktada stdin ve stdout başvuruda böylece yerde, C # uygulama, sağ başında, bu komut dosyasını çalıştırmak ve sonra bir yerde Süreci örneğini kaydetmek için yeni Süreci oluşturmak var bir kere. Örnek:
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();
Verilerinizi çözmek istiyorsanız o zaman, sadece oluşturduğunuz php sürecinin stdin yazmak ve stdout'ta bir yanıt bekleyin. Bu süreci oluşturma havai fark olabilir çünkü stdin / stdout yaklaşımı kullanarak, yeni bir süreç bazı verileri çözmek istediğiniz her zaman yaratmak çok daha verimli.
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
Burada Yasal Uyarı, bu kod herhangi bir test değil, ama ben bunu nasıl genel özü olduğunu.
Ben sadece düşündüm başka bir şey, o PHP süreci sona erdirmek için bazı mekanizmalar isteyeceksiniz. Bu Process.Kill kullanmak için Tamam olabilir, ama çözme herhangi bir dosya IO, ya da bir şekilde php script bir kesme sinyali göndermek isteyebilirsiniz kritik bir şey yaparsa. Olabilir