Grandioso Posted December 29, 2011 Share Posted December 29, 2011 Hey guys. I'll be doing a frontend for some router testing scripts and I'll need to launch some shell scripts in php. The user will be allowed to check some checkboxes - choose which tests to run and run them using a button. I want to show them some kind of "Testing in progress" string and then show them the result when it's done. What do you think is the best solution ? I was thinking the shell script should create the whole output in some sensible form and then I would just parse it. Should I use a database for storing the error strings, or do you think they should be a part of the script ? Also, I would like to do it with AJAX (I never did it before and I could use some experience). So I need some advice on this. I want the form to disappear after the button was pressed, replace it with the "testing in progress" string (or maybe a temporary popup window would be better) and then if the script is done, display the result. I guess I need to use the shell_exec command. What would you suggest ? btw I guess there is no way to run a script on a different server than one which runs the webpage, is there ? Quote Link to comment https://forums.phpfreaks.com/topic/254037-calling-shell-scripts-and-waiting-for-output/ Share on other sites More sharing options...
btherl Posted December 29, 2011 Share Posted December 29, 2011 There is no simple way to run a script on a different server. If you want maximum reliability then you can create a db table which stores the command, who triggered it and when, which server it's running on, its output (or the name of a file containing the full output), any errors, and anything else interesting. The front end adds an entry to that table, and the AJAX calls a simple script that checks if the db table entry is marked as "done". In the meantime, another job, which can run on another server, polls that db table and starts anything that needs starting. The most complex script is the one that runs each job, monitors it and makes sure any error status is recorded. The job may crash altogether, in which case the monitor needs to detect that and record it in that db table. If the script succeeds then the job itself can update the db table. Quote Link to comment https://forums.phpfreaks.com/topic/254037-calling-shell-scripts-and-waiting-for-output/#findComment-1302375 Share on other sites More sharing options...
Grandioso Posted January 4, 2012 Author Share Posted January 4, 2012 The scripts will only run on one server, I was just asking out of curiosity. Thanks for the help. I think I'll need to check some AJAX tutorials, because I have no idea where to start. Currently I was thinking about doing it like this: The form will be handled by another script, which will display the names of all tests and put a thick next to the ones that have succeeded. The test will be assigned some ID and a row in the database. The script will update the database record after each test. The page will check this database every second and update the content. Quote Link to comment https://forums.phpfreaks.com/topic/254037-calling-shell-scripts-and-waiting-for-output/#findComment-1304261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.