I have a REST API backed by PHP, that calls a C program. Depending on the inputs, the C program returns JSON data, and the PHP reads the output and directly sends it back to the client.
The code is essentially:
$command = $binary . " " . $parameters;
$output = shell_exec($command);
echo $output;
For each invocation of the API, PHP starts up the program, does some processing, and ends.
I would like to make this more efficient by making the C program run as a daemon, and then have the PHP backend call into this daemon.
Also, I might be migrating to a Python web framework, so I would like something that is cross-platform from the client side.
My gut reaction is to simply do it over sockets, since then I can put the daemon anywhere (it would for the foreseeable future be located on the same web server, but I could move it off eventually). But is sockets efficient enough, or is there something else that is considered a better practice?