Can a PHP script talk to a C program?
I have a potential new project, it's an embedded Linux device that needs a web interface. The开发者_StackOverflow社区 code for the application will be running as a single process in C. The web interface needs to be able to configure various variables in the C program. Is there a good mechanism in PHP for communicating values from a PHP script to a C process?
TY, Fred
Yes i have done it before.
You need to use TCP connections between the web server and the C application and then the two can communicate different messages and commands to each other
There are probably better ways but if the data isn't updated very often, you can use files.
Second solution is to use PHP functions like exec()
to execute you C application with proper parameters.
You can check RPC (remote procedure call) http://en.wikipedia.org/wiki/XML-RPC that could help. I believe that easiest way to do that is using PHP exec() function, you would be able to execute c program via PHP, potential issue here is that once you run C program via PHP and PHP pass vars to C they cannot communicate any more, of course C can return some values and PHP can capture it but that is it. To pass more values you would have to execute C program all over again. Other method would be to write your C application as PHP plugin.
精彩评论