I am having an application in which there is a dumper action which continuously retrieves an xml stream from a web service parse it and then dumps it into a mysql DB.
Right now i am doing all the dumping action in the UI and its a real pain to both dump the data and manipulate it.
So i made a separate CLI script which will take care of the dumping action and the front end can just poll the DB every second to see if it has new data which would be a much more trivial way of doing it. But the only problem now is that i am not able to control the cli script from the web UI.
That is i want to be able to start the dumping action and stop it from the UI. I tried this method that ive seen somewhere before
while(true) {
if(file_exist($file)) {
//do action
} else {
break;
}
}
so ill delete the file on stop action from the frontend and there are variable problems with this method and all this doesnt seem like the correct way of doing it. So is there a better way to control Command line scripts from the Web page UI.
Since the script already has database access, why don’t you create a control table for the CLI script, containing the actions it should perform? You the pull the record from the table every time the script loops.
You’d be able to fix it with one row (maybe you already got a settings table which you could (ab)use), containing a single command. If it’s a 1 or “run” or true or whatever you like, your script continues, otherwise it stops.
Then, from the Web UI you can “send” the commands, which will be stored in the specified table.