views:

53

answers:

2

I'm using a local server on my laptop to control a C# program via PHP. Basically I'm taking a POST passed to my web server, and using it as the parameters for a command line program. My code is essentially this:

$parameters = $_POST['parameters'];
system('C://THEFILEPATH/myprogram.exe ' . $parameters);

The problem is that this causes myprogram.exe to stop and start every time I want to pass something to it. Since a good portion of my program is initialization, it causes a bit of unnecessary lag. Is there a way to run myprogram.exe via PHP, and pass it variables as it continues to run instead of starting it anew each time?

Thanks!

A: 

http://www.php.net/manual/en/function.proc-open.php This provides bidirectional support (reading and writing). I'm not sure how tested this is on Windows, though. It says later on there:

Windows compatibility: Descriptors beyond 2 (stderr) are made available to the child process as inheritable handles, but since the Windows architecture does not associate file descriptor numbers with low-level handles, the child process does not (yet) have a means of accessing those handles. Stdin, stdout and stderr work as expected.

So you should be able to write to it just like a file.

0x90
A: 

take the input and write it to a file. your myprogram should read the file every once in a while and delete all read input so that the file works like a queue. if you want to always run your program and while running receive your input then you should consider implementing a component for listening to a special network port.

ITroubs