Opening a "terminal window" from php

KenHorse

Member
Here's the scenario:

From a php created webpage, I'd like to open some sort of terminal window that runs a python script. My python script includes a progress indicator ("command line" type) and then close the window after the script is finished.

The problem I've seen with calling shell or shellexec from PHP is any output from the called script is not displayed until control is returned to the calling php script, hence why I want to do something like this
 
PHP runs on your web server; any animation you display - your progress bar in this case - has to run on the user's web browser. This makes your requirement pretty complicated.

You need an endpoint on your server which the user can call which means "start the process". Call this "start.php". "start.php" has to start the process, then instantly return some process ID that uniquely identifies the user's process. Starting a background process is a whole other box of pain, since PHP is designed to finish processing *then* respond to the request.

You need an endpoint on your server which the user can call which means "check the process". Call this "checkstatus.php". This endpoint will accept the process ID returned above, and return some measurement of how far along the process is.

You need a client side (eg javascript) script that will periodically call "checkstatus.php" and use the response to render a progress bar.

You could also do this using web sockets, but you'd need someone else to show you through that.

All honesty, I'd recommend against trying to give your users real time feedback from a web service.
 
Back
Top