I have a computational terminal program that I need to interact with using a php webpage. I can do this in JAVA using getRuntime().exec(…) and then creating pipes that read from and write to the process, and the process will exist between requests. But I am not sure if it can be done with PHP as I dont think proc_open keeps the process alive during requests?
Here is the flow of the webpage I am creating. First the user will enter a command on the webpage, which will be fed to a the terminal program that performs the computation and then the answer is returned to the user. I will use AJAX for the request so that the answer is returned without refreshing the page.
Now my issue is that I need to interact with the same process on the next request rather than start a new one. This is because the terminal program has state. That is I can set variables in it like this – X = 5;
So on my first AJAX call to the program I pass
X = 5;
and the output from the program that is returned to the user’s browser is –
X = 5
Then on my next AJAX request I pass
Y = X + 5;
and then the program should output
Y = 10
which gets passed back to the users browser.
But it is my understanding the the proc_open function does not maintain state between requests. I understand that the process is closed when the server responds to the user’s request. Is this correct? And if so is there any way to do what I need to do using PHP?
You’ll want to look into
$_SESSIONs. Since PHP doesn’t have a concept of maintaining state sessions, this is how you can pass information from request to request.