I have been playing around with the idea of emulating a command line with javascript/PHP. The basic idea is, I want to be able to run a c++ program like I would on a command line.
I made a basic console with javascript, and a code parser for C++ to add certain things to the original source to enable my PHP program execution script to recognize when there is an input request or when the program ends. Now, I want to be able to communicate between the javascript(console web app) and PHP(program execution) in such a way that PHP can tell javascript what to display(output) and request input.
I had planned it with AJAX. Once the user would enter the program run command on the console(javascript end), it would switch to execution state and send a request to a PHP script with the program name. The script would start the process and end by echoing the result. Based on the request response, javascript would again send a request to the PHP script, which would pick off where it left and echo another result for the javascript to pick up on. And this would go on until the PHP script echoed an error string or a termination string.
After many naive attempts with AJAX, I know my idea was completely wrong. I've been wondering if there is another method to communicate between the two ends. Is there a way by which I can save my PHP script's state (resources, variables and file handles) such that whenever I send a request to it from the javascript end, I can get output continuing from where I last left off?
I haven't been able to find one yet, which leads me to believe this approach is wishful thinking.
I would really appreciate some insight.