I have two application - a php web application and c program. The php app has to send data to the c program which returns results. The c program has to run all the time in a cycle (while(true), because it has to hold data of previous input in memory.
I handle the problem passing data between c and php by using files (input & output files). If there is a change in my web application my php script update a file, that is read by my c program. The output is written into an other file. The web application is looking all the time for changes.
I think it is not the smartest solution to solve a problem like this. Probaly its a lot not necessary file access.
With inspiration and help from following thread i thought using a kind of c php server bridge could be a good solution.
How to pass value and run c program in php( web application)
Passing data between PHP and C executable in linux
I've started with mongoose. Mongoose is a very lightweight webserver. My current idea is that my web application would send data via POST directly to my c program. The request is handle by the mongoose webserver. Is this the way to go? Or would be a better solution to split it in two application 1) a webserver that handle input output - the variable between both program is passed by shared memory 2) my current c program for my operation (input / output via shared memory)
Or is this all the complete wrong way and a) i should stick to my file solution b) there is a even better way? I am sorry for all this question but i am pretty new to c and struggle a lot and not feeling really confident with all this.
Edit
I try to be more specific what my c program does. Basically its a simulation. It is like a stateflow that have around 20-40 inputs that are all integer and most of the time just 0 or 1. The program acts on the base of the inputs and of previous states. The inputs are reset after one iteration by changing the input file to origin state.
The output file is updated all the time with the corresponding output values (like var = 1 var2 = 3)